From 011fe9814f7be7df7212229fa4f8393e03829cb7 Mon Sep 17 00:00:00 2001 From: Larry D'Anna Date: Fri, 26 Feb 2010 23:52:13 -0500 Subject: git-push: fix an advice message so it goes to stderr These sort of messages typically go to the standard error. Signed-off-by: Larry D'Anna Signed-off-by: Junio C Hamano diff --git a/builtin-push.c b/builtin-push.c index 5633f0a..0a27072 100644 --- a/builtin-push.c +++ b/builtin-push.c @@ -124,9 +124,9 @@ static int push_with_options(struct transport *transport, int flags) return 0; if (nonfastforward && advice_push_nonfastforward) { - printf("To prevent you from losing history, non-fast-forward updates were rejected\n" - "Merge the remote changes before pushing again. See the 'Note about\n" - "fast-forwards' section of 'git push --help' for details.\n"); + fprintf(stderr, "To prevent you from losing history, non-fast-forward updates were rejected\n" + "Merge the remote changes before pushing again. See the 'Note about\n" + "fast-forwards' section of 'git push --help' for details.\n"); } return 1; -- cgit v0.10.2-6-g49f6 From 60cfeb8e95d859bf250804c7981e8481e297c3b6 Mon Sep 17 00:00:00 2001 From: Larry D'Anna Date: Fri, 26 Feb 2010 23:52:14 -0500 Subject: git-push: send "To " messages to the standard output in --porcelain mode git-push prints the line "To " before above each of the ref status lines. In --porcelain mode, these "To " lines go to the standard error, but the ref status lines go to the standard output. This makes it difficult for the process reading standard output to know which ref status lines correspond to which remote. This patch sends the "To " lines to the the standard output instead. Signed-off-by: Larry D'Anna Signed-off-by: Junio C Hamano diff --git a/transport.c b/transport.c index 3846aac..fb653c6 100644 --- a/transport.c +++ b/transport.c @@ -675,7 +675,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain) static int print_one_push_status(struct ref *ref, const char *dest, int count, int porcelain) { if (!count) - fprintf(stderr, "To %s\n", dest); + fprintf(porcelain ? stdout : stderr, "To %s\n", dest); switch(ref->status) { case REF_STATUS_NONE: -- cgit v0.10.2-6-g49f6 From 77555854be6e7fbce07c9ded30ea859b54699be0 Mon Sep 17 00:00:00 2001 From: Larry D'Anna Date: Fri, 26 Feb 2010 23:52:15 -0500 Subject: git-push: make git push --porcelain print "Done" The script calling git push --porcelain --dry-run can see clearly from the output if an update was rejected. However, it will probably need to distinguish this condition from the push failing for other reasons, such as the remote not being reachable. This patch modifies git push --porcelain to print "Done" after the rest of its output unless any errors have occurred. For the purpose of the "Done" line, knowing a ref will be rejected in a --dry-run does not count as an error. Actual rejections in non --dry-run pushes do count as errors. Signed-off-by: Larry D'Anna Acked-by: Tay Ray Chuan Signed-off-by: Junio C Hamano diff --git a/builtin-send-pack.c b/builtin-send-pack.c index 76c7206..078bc3e 100644 --- a/builtin-send-pack.c +++ b/builtin-send-pack.c @@ -476,6 +476,10 @@ int send_pack(struct send_pack_args *args, if (ret < 0) return ret; + + if (args->porcelain) + return 0; + for (ref = remote_refs; ref; ref = ref->next) { switch (ref->status) { case REF_STATUS_NONE: diff --git a/send-pack.h b/send-pack.h index 28141ac..60b4ba6 100644 --- a/send-pack.h +++ b/send-pack.h @@ -4,6 +4,7 @@ struct send_pack_args { unsigned verbose:1, quiet:1, + porcelain:1, send_mirror:1, force_update:1, use_thin_pack:1, diff --git a/transport.c b/transport.c index fb653c6..260350b 100644 --- a/transport.c +++ b/transport.c @@ -791,6 +791,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re args.verbose = !!(flags & TRANSPORT_PUSH_VERBOSE); args.quiet = !!(flags & TRANSPORT_PUSH_QUIET); args.dry_run = !!(flags & TRANSPORT_PUSH_DRY_RUN); + args.porcelain = !!(flags & TRANSPORT_PUSH_PORCELAIN); ret = send_pack(&args, data->fd, data->conn, remote_refs, &data->extra_have); @@ -1035,7 +1036,7 @@ int transport_push(struct transport *transport, int quiet = flags & TRANSPORT_PUSH_QUIET; int porcelain = flags & TRANSPORT_PUSH_PORCELAIN; int pretend = flags & TRANSPORT_PUSH_DRY_RUN; - int ret, err; + int push_ret, ret, err; if (flags & TRANSPORT_PUSH_ALL) match_flags |= MATCH_REFS_ALL; @@ -1051,10 +1052,9 @@ int transport_push(struct transport *transport, flags & TRANSPORT_PUSH_MIRROR, flags & TRANSPORT_PUSH_FORCE); - ret = transport->push_refs(transport, remote_refs, flags); + push_ret = transport->push_refs(transport, remote_refs, flags); err = push_had_errors(remote_refs); - - ret |= err; + ret = push_ret | err; if (!quiet || err) print_push_status(transport->url, remote_refs, @@ -1070,8 +1070,11 @@ int transport_push(struct transport *transport, update_tracking_ref(transport->remote, ref, verbose); } - if (!quiet && !ret && !refs_pushed(remote_refs)) + if (porcelain && !push_ret) + puts("Done"); + else if (!quiet && !ret && !refs_pushed(remote_refs)) fprintf(stderr, "Everything up-to-date\n"); + return ret; } return 1; -- cgit v0.10.2-6-g49f6 From fbe4f447ec60ffa760cfb586708ddbddee789733 Mon Sep 17 00:00:00 2001 From: Larry D'Anna Date: Fri, 26 Feb 2010 23:52:16 -0500 Subject: git-push: add tests for git push --porcelain Verify that the output format is correct for successful, rejected, and flagrantly erroneous pushes. Signed-off-by: Larry D'Anna Signed-off-by: Junio C Hamano diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 0f04b2e..11adb0b 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -660,4 +660,54 @@ test_expect_success 'push with branches containing #' ' git checkout master ' +test_expect_success 'push --porcelain' ' + mk_empty && + echo >.git/foo "To testrepo" && + echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new branch]" && + echo >>.git/foo "Done" && + git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master && + ( + cd testrepo && + r=$(git show-ref -s --verify refs/remotes/origin/master) && + test "z$r" = "z$the_commit" && + test 1 = $(git for-each-ref refs/remotes/origin | wc -l) + ) && + diff -q .git/foo .git/bar +' + +test_expect_success 'push --porcelain bad url' ' + mk_empty && + test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master && + test_must_fail grep -q Done .git/bar +' + +test_expect_success 'push --porcelain rejected' ' + mk_empty && + git push testrepo refs/heads/master:refs/remotes/origin/master && + (cd testrepo && + git reset --hard origin/master^ + git config receive.denyCurrentBranch true) && + + echo >.git/foo "To testrepo" && + echo >>.git/foo "! refs/heads/master:refs/heads/master [remote rejected] (branch is currently checked out)" && + + test_must_fail git push >.git/bar --porcelain testrepo refs/heads/master:refs/heads/master && + diff -q .git/foo .git/bar +' + +test_expect_success 'push --porcelain --dry-run rejected' ' + mk_empty && + git push testrepo refs/heads/master:refs/remotes/origin/master && + (cd testrepo && + git reset --hard origin/master + git config receive.denyCurrentBranch true) && + + echo >.git/foo "To testrepo" && + echo >>.git/foo "! refs/heads/master^:refs/heads/master [rejected] (non-fast-forward)" && + echo >>.git/foo "Done" && + + test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/master^:refs/heads/master && + diff -q .git/foo .git/bar +' + test_done -- cgit v0.10.2-6-g49f6 From c296134d038fe6d836fe3848e0b342d920933683 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 11 Mar 2010 21:51:57 -0800 Subject: t5516: Use test_cmp when appropriate Consistently using test_cmp would make debugging test scripts far easier, as output from them run under "-v" option becomes readable. Besides, some platforms' "diff" implementations lack "-q" option. Signed-off-by: Junio C Hamano diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 11adb0b..2de98e6 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -672,7 +672,7 @@ test_expect_success 'push --porcelain' ' test "z$r" = "z$the_commit" && test 1 = $(git for-each-ref refs/remotes/origin | wc -l) ) && - diff -q .git/foo .git/bar + test_cmp .git/foo .git/bar ' test_expect_success 'push --porcelain bad url' ' @@ -692,7 +692,7 @@ test_expect_success 'push --porcelain rejected' ' echo >>.git/foo "! refs/heads/master:refs/heads/master [remote rejected] (branch is currently checked out)" && test_must_fail git push >.git/bar --porcelain testrepo refs/heads/master:refs/heads/master && - diff -q .git/foo .git/bar + test_cmp .git/foo .git/bar ' test_expect_success 'push --porcelain --dry-run rejected' ' @@ -707,7 +707,7 @@ test_expect_success 'push --porcelain --dry-run rejected' ' echo >>.git/foo "Done" && test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/master^:refs/heads/master && - diff -q .git/foo .git/bar + test_cmp .git/foo .git/bar ' test_done -- cgit v0.10.2-6-g49f6