From: Junio C Hamano Date: Sun, 29 Jan 2012 21:18:54 +0000 (-0800) Subject: Merge branch 'sp/smart-http-failure-to-push' X-Git-Tag: v1.7.10-rc0~139 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/2bbf77dde2b47f2b8c9769c4d64f7f2f591d1e99?hp=-c Merge branch 'sp/smart-http-failure-to-push' * sp/smart-http-failure-to-push: remote-curl: Fix push status report when all branches fail --- 2bbf77dde2b47f2b8c9769c4d64f7f2f591d1e99 diff --combined remote-curl.c index bcbc7fba4e,f48485931f..d159fe7f34 --- a/remote-curl.c +++ b/remote-curl.c @@@ -115,7 -115,7 +115,7 @@@ static struct discovery* discover_refs( http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE); /* try again with "plain" url (no ? or & appended) */ - if (http_ret != HTTP_OK) { + if (http_ret != HTTP_OK && http_ret != HTTP_NOAUTH) { free(refs_url); strbuf_reset(&buffer); @@@ -188,7 -188,7 +188,7 @@@ static int write_discovery(int in, int return err; } -static struct ref *parse_git_refs(struct discovery *heads) +static struct ref *parse_git_refs(struct discovery *heads, int for_push) { struct ref *list = NULL; struct async async; @@@ -200,8 -200,7 +200,8 @@@ if (start_async(&async)) die("cannot start thread to parse advertised refs"); - get_remote_heads(async.out, &list, 0, NULL, 0, NULL); + get_remote_heads(async.out, &list, + for_push ? REF_NORMAL : 0, NULL); close(async.out); if (finish_async(&async)) die("ref parsing thread failed"); @@@ -269,7 -268,7 +269,7 @@@ static struct ref *get_refs(int for_pus heads = discover_refs("git-upload-pack"); if (heads->proto_git) - return parse_git_refs(heads); + return parse_git_refs(heads, for_push); return parse_info_refs(heads); } @@@ -574,14 -573,7 +574,14 @@@ static int rpc_service(struct rpc_stat close(client.in); client.in = -1; - strbuf_read(&rpc->result, client.out, 0); + if (!err) { + strbuf_read(&rpc->result, client.out, 0); + } else { + char buf[4096]; + for (;;) + if (xread(client.out, buf, sizeof(buf)) <= 0) + break; + } close(client.out); client.out = -1; @@@ -770,9 -762,7 +770,9 @@@ static int push_git(struct discovery *h argv[argc++] = "--thin"; if (options.dry_run) argv[argc++] = "--dry-run"; - if (options.verbosity > 1) + if (options.verbosity == 0) + argv[argc++] = "--quiet"; + else if (options.verbosity > 1) argv[argc++] = "--verbose"; argv[argc++] = url; for (i = 0; i < nr_spec; i++) @@@ -807,7 -797,7 +807,7 @@@ static int push(int nr_spec, char **spe static void parse_push(struct strbuf *buf) { char **specs = NULL; - int alloc_spec = 0, nr_spec = 0, i; + int alloc_spec = 0, nr_spec = 0, i, ret; do { if (!prefixcmp(buf->buf, "push ")) { @@@ -824,12 -814,13 +824,13 @@@ break; } while (1); - if (push(nr_spec, specs)) - exit(128); /* error already reported */ - + ret = push(nr_spec, specs); printf("\n"); fflush(stdout); + if (ret) + exit(128); /* error already reported */ + free_specs: for (i = 0; i < nr_spec; i++) free(specs[i]); @@@ -862,17 -853,10 +863,17 @@@ int main(int argc, const char **argv url = strbuf_detach(&buf, NULL); - http_init(remote); + http_init(remote, url, 0); do { - if (strbuf_getline(&buf, stdin, '\n') == EOF) + if (strbuf_getline(&buf, stdin, '\n') == EOF) { + if (ferror(stdin)) + fprintf(stderr, "Error reading command stream\n"); + else + fprintf(stderr, "Unexpected end of command stream\n"); + return 1; + } + if (buf.len == 0) break; if (!prefixcmp(buf.buf, "fetch ")) { if (nongit) @@@ -912,7 -896,6 +913,7 @@@ printf("\n"); fflush(stdout); } else { + fprintf(stderr, "Unknown command '%s'\n", buf.buf); return 1; } strbuf_reset(&buf); diff --combined t/t5541-http-push.sh index 6c9ec6f117,b8f4c2ac3c..d66ed24508 --- a/t/t5541-http-push.sh +++ b/t/t5541-http-push.sh @@@ -14,7 -14,6 +14,7 @@@ f ROOT_PATH="$PWD" LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5541'} . "$TEST_DIRECTORY"/lib-httpd.sh +. "$TEST_DIRECTORY"/lib-terminal.sh start_httpd test_expect_success 'setup remote repository' ' @@@ -96,6 -95,32 +96,32 @@@ test_expect_success 'create and delete test_must_fail git show-ref --verify refs/remotes/origin/dev ' + cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <exp < dev2 (hook declined) + error: failed to push some refs to 'http://127.0.0.1:5541/smart/test_repo.git' + EOF + + test_expect_success 'rejected update prints status' ' + cd "$ROOT_PATH"/test_repo_clone && + git checkout -b dev2 && + : >path4 && + git add path4 && + test_tick && + git commit -m dev2 && + test_must_fail git push origin dev2 2>act && + sed -e "/^remote: /s/ *$//" cmp && + test_cmp exp cmp + ' + rm -f "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" + cat >exp <&1 | tee output && + test_cmp /dev/null output +' + stop_httpd test_done