Skip to content

Commit 0b9865f

Browse files
jiangxingitster
authored andcommitted
t5574: test porcelain output of atomic fetch
The test case "fetch porcelain output" checks output of the fetch command. The error output must be empty with the follow assertion: test_must_be_empty stderr But this assertion fails if using atomic fetch. Refactor this test case to use different fetch options by splitting it into three test cases. 1. "setup for fetch porcelain output". 2. "fetch porcelain output": for non-atomic fetch. 3. "fetch porcelain output (atomic)": for atomic fetch. Add new command "test_commit ..." in the first test case, so that if we run these test cases individually (--run=4-6), "git rev-parse HEAD~" command will work properly. Run the above test cases, we can find that one test case has a known breakage, as shown below: ok 4 - setup for fetch porcelain output ok 5 - fetch porcelain output # TODO known breakage vanished not ok 6 - fetch porcelain output (atomic) # TODO known breakage The failed test case has an error message with only the error prompt but no message body, as follows: 'stderr' is not empty, it contains: error: In a later commit, we will fix this issue. Signed-off-by: Jiang Xin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 813d9a9 commit 0b9865f

File tree

1 file changed

+58
-39
lines changed

1 file changed

+58
-39
lines changed

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_failure "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)