Skip to content

Commit deb67d1

Browse files
committed
Merge branch 'jx/fetch-atomic-error-message-fix'
"git fetch --atomic" issued an unnecessary empty error message, which has been corrected. * jx/fetch-atomic-error-message-fix: fetch: no redundant error message for atomic fetch t5574: test porcelain output of atomic fetch
2 parents a29e8b6 + 18ce489 commit deb67d1

File tree

2 files changed

+59
-44
lines changed

2 files changed

+59
-44
lines changed

builtin/fetch.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,7 @@ static int do_fetch(struct transport *transport,
16511651
if (atomic_fetch) {
16521652
transaction = ref_transaction_begin(&err);
16531653
if (!transaction) {
1654-
retcode = error("%s", err.buf);
1654+
retcode = -1;
16551655
goto cleanup;
16561656
}
16571657
}
@@ -1711,7 +1711,6 @@ static int do_fetch(struct transport *transport,
17111711

17121712
retcode = ref_transaction_commit(transaction, &err);
17131713
if (retcode) {
1714-
error("%s", err.buf);
17151714
ref_transaction_free(transaction);
17161715
transaction = NULL;
17171716
goto cleanup;
@@ -1775,9 +1774,14 @@ static int do_fetch(struct transport *transport,
17751774
}
17761775

17771776
cleanup:
1778-
if (retcode && transaction) {
1779-
ref_transaction_abort(transaction, &err);
1780-
error("%s", err.buf);
1777+
if (retcode) {
1778+
if (err.len) {
1779+
error("%s", err.buf);
1780+
strbuf_reset(&err);
1781+
}
1782+
if (transaction && ref_transaction_abort(transaction, &err) &&
1783+
err.len)
1784+
error("%s", err.buf);
17811785
}
17821786

17831787
display_state_release(&display_state);

t/t5574-fetch-output.sh

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ test_expect_success 'fetch compact output' '
6161
test_cmp expect actual
6262
'
6363

64-
test_expect_success 'fetch porcelain output' '
65-
test_when_finished "rm -rf porcelain" &&
66-
64+
test_expect_success 'setup for fetch porcelain output' '
6765
# Set up a bunch of references that we can use to demonstrate different
6866
# kinds of flag symbols in the output format.
67+
test_commit commit-for-porcelain-output &&
6968
MAIN_OLD=$(git rev-parse HEAD) &&
7069
git branch "fast-forward" &&
7170
git branch "deleted-branch" &&
@@ -74,15 +73,10 @@ test_expect_success 'fetch porcelain output' '
7473
FORCE_UPDATED_OLD=$(git rev-parse HEAD) &&
7574
git checkout main &&
7675
77-
# Clone and pre-seed the repositories. We fetch references into two
78-
# namespaces so that we can test that rejected and force-updated
79-
# references are reported properly.
80-
refspecs="refs/heads/*:refs/unforced/* +refs/heads/*:refs/forced/*" &&
81-
git clone . porcelain &&
82-
git -C porcelain fetch origin $refspecs &&
76+
# Backup to preseed.git
77+
git clone --mirror . preseed.git &&
8378
84-
# Now that we have set up the client repositories we can change our
85-
# local references.
79+
# Continue changing our local references.
8680
git branch new-branch &&
8781
git branch -d deleted-branch &&
8882
git checkout fast-forward &&
@@ -91,36 +85,53 @@ test_expect_success 'fetch porcelain output' '
9185
git checkout force-updated &&
9286
git reset --hard HEAD~ &&
9387
test_commit --no-tag force-update-new &&
94-
FORCE_UPDATED_NEW=$(git rev-parse HEAD) &&
95-
96-
cat >expect <<-EOF &&
97-
- $MAIN_OLD $ZERO_OID refs/forced/deleted-branch
98-
- $MAIN_OLD $ZERO_OID refs/unforced/deleted-branch
99-
$MAIN_OLD $FAST_FORWARD_NEW refs/unforced/fast-forward
100-
! $FORCE_UPDATED_OLD $FORCE_UPDATED_NEW refs/unforced/force-updated
101-
* $ZERO_OID $MAIN_OLD refs/unforced/new-branch
102-
$MAIN_OLD $FAST_FORWARD_NEW refs/forced/fast-forward
103-
+ $FORCE_UPDATED_OLD $FORCE_UPDATED_NEW refs/forced/force-updated
104-
* $ZERO_OID $MAIN_OLD refs/forced/new-branch
105-
$MAIN_OLD $FAST_FORWARD_NEW refs/remotes/origin/fast-forward
106-
+ $FORCE_UPDATED_OLD $FORCE_UPDATED_NEW refs/remotes/origin/force-updated
107-
* $ZERO_OID $MAIN_OLD refs/remotes/origin/new-branch
108-
EOF
109-
110-
# Execute a dry-run fetch first. We do this to assert that the dry-run
111-
# and non-dry-run fetches produces the same output. Execution of the
112-
# fetch is expected to fail as we have a rejected reference update.
113-
test_must_fail git -C porcelain fetch \
114-
--porcelain --dry-run --prune origin $refspecs >actual &&
115-
test_cmp expect actual &&
116-
117-
# And now we perform a non-dry-run fetch.
118-
test_must_fail git -C porcelain fetch \
119-
--porcelain --prune origin $refspecs >actual 2>stderr &&
120-
test_cmp expect actual &&
121-
test_must_be_empty stderr
88+
FORCE_UPDATED_NEW=$(git rev-parse HEAD)
12289
'
12390

91+
for opt in "" "--atomic"
92+
do
93+
test_expect_success "fetch porcelain output ${opt:+(atomic)}" '
94+
test_when_finished "rm -rf porcelain" &&
95+
96+
# Clone and pre-seed the repositories. We fetch references into two
97+
# namespaces so that we can test that rejected and force-updated
98+
# references are reported properly.
99+
refspecs="refs/heads/*:refs/unforced/* +refs/heads/*:refs/forced/*" &&
100+
git clone preseed.git porcelain &&
101+
git -C porcelain fetch origin $opt $refspecs &&
102+
103+
cat >expect <<-EOF &&
104+
- $MAIN_OLD $ZERO_OID refs/forced/deleted-branch
105+
- $MAIN_OLD $ZERO_OID refs/unforced/deleted-branch
106+
$MAIN_OLD $FAST_FORWARD_NEW refs/unforced/fast-forward
107+
! $FORCE_UPDATED_OLD $FORCE_UPDATED_NEW refs/unforced/force-updated
108+
* $ZERO_OID $MAIN_OLD refs/unforced/new-branch
109+
$MAIN_OLD $FAST_FORWARD_NEW refs/forced/fast-forward
110+
+ $FORCE_UPDATED_OLD $FORCE_UPDATED_NEW refs/forced/force-updated
111+
* $ZERO_OID $MAIN_OLD refs/forced/new-branch
112+
$MAIN_OLD $FAST_FORWARD_NEW refs/remotes/origin/fast-forward
113+
+ $FORCE_UPDATED_OLD $FORCE_UPDATED_NEW refs/remotes/origin/force-updated
114+
* $ZERO_OID $MAIN_OLD refs/remotes/origin/new-branch
115+
EOF
116+
117+
# Change the URL of the repository to fetch different references.
118+
git -C porcelain remote set-url origin .. &&
119+
120+
# Execute a dry-run fetch first. We do this to assert that the dry-run
121+
# and non-dry-run fetches produces the same output. Execution of the
122+
# fetch is expected to fail as we have a rejected reference update.
123+
test_must_fail git -C porcelain fetch $opt \
124+
--porcelain --dry-run --prune origin $refspecs >actual &&
125+
test_cmp expect actual &&
126+
127+
# And now we perform a non-dry-run fetch.
128+
test_must_fail git -C porcelain fetch $opt \
129+
--porcelain --prune origin $refspecs >actual 2>stderr &&
130+
test_cmp expect actual &&
131+
test_must_be_empty stderr
132+
'
133+
done
134+
124135
test_expect_success 'fetch porcelain with multiple remotes' '
125136
test_when_finished "rm -rf porcelain" &&
126137

0 commit comments

Comments
 (0)