Skip to content

Commit 7fdabdf

Browse files
committed
Merge branch 'jx/fetch-atomic-error-message-fix' into seen
"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 8e602fc + e10fa19 commit 7fdabdf

File tree

2 files changed

+59
-42
lines changed

2 files changed

+59
-42
lines changed

builtin/fetch.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,10 +1773,8 @@ static int do_fetch(struct transport *transport,
17731773
}
17741774

17751775
cleanup:
1776-
if (retcode && transaction) {
1777-
ref_transaction_abort(transaction, &err);
1776+
if (retcode && transaction && ref_transaction_abort(transaction, &err))
17781777
error("%s", err.buf);
1779-
}
17801778

17811779
display_state_release(&display_state);
17821780
close_fetch_head(&fetch_head);

t/t5574-fetch-output.sh

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

0 commit comments

Comments
 (0)