Skip to content

Commit 66bce02

Browse files
committed
Merge branch 'ld/push-porcelain'
* ld/push-porcelain: t5516: Use test_cmp when appropriate git-push: add tests for git push --porcelain git-push: make git push --porcelain print "Done" git-push: send "To <remoteurl>" messages to the standard output in --porcelain mode git-push: fix an advice message so it goes to stderr Conflicts: transport.c
2 parents 2949151 + c296134 commit 66bce02

File tree

5 files changed

+67
-9
lines changed

5 files changed

+67
-9
lines changed

builtin/push.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ static int push_with_options(struct transport *transport, int flags)
124124
return 0;
125125

126126
if (nonfastforward && advice_push_nonfastforward) {
127-
printf("To prevent you from losing history, non-fast-forward updates were rejected\n"
128-
"Merge the remote changes before pushing again. See the 'Note about\n"
129-
"fast-forwards' section of 'git push --help' for details.\n");
127+
fprintf(stderr, "To prevent you from losing history, non-fast-forward updates were rejected\n"
128+
"Merge the remote changes before pushing again. See the 'Note about\n"
129+
"fast-forwards' section of 'git push --help' for details.\n");
130130
}
131131

132132
return 1;

builtin/send-pack.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ int send_pack(struct send_pack_args *args,
361361

362362
if (ret < 0)
363363
return ret;
364+
365+
if (args->porcelain)
366+
return 0;
367+
364368
for (ref = remote_refs; ref; ref = ref->next) {
365369
switch (ref->status) {
366370
case REF_STATUS_NONE:

send-pack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
struct send_pack_args {
55
unsigned verbose:1,
66
quiet:1,
7+
porcelain:1,
78
send_mirror:1,
89
force_update:1,
910
use_thin_pack:1,

t/t5516-fetch-push.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,4 +660,54 @@ test_expect_success 'push with branches containing #' '
660660
git checkout master
661661
'
662662

663+
test_expect_success 'push --porcelain' '
664+
mk_empty &&
665+
echo >.git/foo "To testrepo" &&
666+
echo >>.git/foo "* refs/heads/master:refs/remotes/origin/master [new branch]" &&
667+
echo >>.git/foo "Done" &&
668+
git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master &&
669+
(
670+
cd testrepo &&
671+
r=$(git show-ref -s --verify refs/remotes/origin/master) &&
672+
test "z$r" = "z$the_commit" &&
673+
test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
674+
) &&
675+
test_cmp .git/foo .git/bar
676+
'
677+
678+
test_expect_success 'push --porcelain bad url' '
679+
mk_empty &&
680+
test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master &&
681+
test_must_fail grep -q Done .git/bar
682+
'
683+
684+
test_expect_success 'push --porcelain rejected' '
685+
mk_empty &&
686+
git push testrepo refs/heads/master:refs/remotes/origin/master &&
687+
(cd testrepo &&
688+
git reset --hard origin/master^
689+
git config receive.denyCurrentBranch true) &&
690+
691+
echo >.git/foo "To testrepo" &&
692+
echo >>.git/foo "! refs/heads/master:refs/heads/master [remote rejected] (branch is currently checked out)" &&
693+
694+
test_must_fail git push >.git/bar --porcelain testrepo refs/heads/master:refs/heads/master &&
695+
test_cmp .git/foo .git/bar
696+
'
697+
698+
test_expect_success 'push --porcelain --dry-run rejected' '
699+
mk_empty &&
700+
git push testrepo refs/heads/master:refs/remotes/origin/master &&
701+
(cd testrepo &&
702+
git reset --hard origin/master
703+
git config receive.denyCurrentBranch true) &&
704+
705+
echo >.git/foo "To testrepo" &&
706+
echo >>.git/foo "! refs/heads/master^:refs/heads/master [rejected] (non-fast-forward)" &&
707+
echo >>.git/foo "Done" &&
708+
709+
test_must_fail git push >.git/bar --porcelain --dry-run testrepo refs/heads/master^:refs/heads/master &&
710+
test_cmp .git/foo .git/bar
711+
'
712+
663713
test_done

transport.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
673673
static int print_one_push_status(struct ref *ref, const char *dest, int count, int porcelain)
674674
{
675675
if (!count)
676-
fprintf(stderr, "To %s\n", dest);
676+
fprintf(porcelain ? stdout : stderr, "To %s\n", dest);
677677

678678
switch(ref->status) {
679679
case REF_STATUS_NONE:
@@ -789,6 +789,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
789789
args.verbose = !!(flags & TRANSPORT_PUSH_VERBOSE);
790790
args.quiet = !!(flags & TRANSPORT_PUSH_QUIET);
791791
args.dry_run = !!(flags & TRANSPORT_PUSH_DRY_RUN);
792+
args.porcelain = !!(flags & TRANSPORT_PUSH_PORCELAIN);
792793

793794
ret = send_pack(&args, data->fd, data->conn, remote_refs,
794795
&data->extra_have);
@@ -1049,7 +1050,7 @@ int transport_push(struct transport *transport,
10491050
int quiet = flags & TRANSPORT_PUSH_QUIET;
10501051
int porcelain = flags & TRANSPORT_PUSH_PORCELAIN;
10511052
int pretend = flags & TRANSPORT_PUSH_DRY_RUN;
1052-
int ret, err;
1053+
int push_ret, ret, err;
10531054

10541055
if (flags & TRANSPORT_PUSH_ALL)
10551056
match_flags |= MATCH_REFS_ALL;
@@ -1065,10 +1066,9 @@ int transport_push(struct transport *transport,
10651066
flags & TRANSPORT_PUSH_MIRROR,
10661067
flags & TRANSPORT_PUSH_FORCE);
10671068

1068-
ret = transport->push_refs(transport, remote_refs, flags);
1069+
push_ret = transport->push_refs(transport, remote_refs, flags);
10691070
err = push_had_errors(remote_refs);
1070-
1071-
ret |= err;
1071+
ret = push_ret | err;
10721072

10731073
if (!quiet || err)
10741074
transport_print_push_status(transport->url, remote_refs,
@@ -1084,8 +1084,11 @@ int transport_push(struct transport *transport,
10841084
transport_update_tracking_ref(transport->remote, ref, verbose);
10851085
}
10861086

1087-
if (!quiet && !ret && !transport_refs_pushed(remote_refs))
1087+
if (porcelain && !push_ret)
1088+
puts("Done");
1089+
else if (!quiet && !ret && !transport_refs_pushed(remote_refs))
10881090
fprintf(stderr, "Everything up-to-date\n");
1091+
10891092
return ret;
10901093
}
10911094
return 1;

0 commit comments

Comments
 (0)