Skip to content

Commit fd72637

Browse files
rybakgitster
authored andcommitted
t2024: fix loose/strict local base branch DWIM test
Test 'loosely defined local base branch is reported correctly' in t2024-checkout-dwim.sh, which was introduced in [1] compares output of two invocations of "git checkout", invoked with two different branches named "strict" and "loose". As per description in [1], the test is validating that output of tracking information for these two branches. This tracking information is printed to standard output: Your branch is behind 'main' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch) The test assumes that the names of the two branches (strict and loose) are in that output, and pipes the output through sed to replace names of the branches with "BRANCHNAME". Command "git checkout", however, outputs the branch name to standard error, not standard output -- see message "Switched to branch '%s'\n" in function "update_refs_for_switch" in "builtin/checkout.c". This means that the two invocations of sed do nothing. Redirect both the standard output and the standard error of "git checkout" for these assertions. Ensure that compared files have the string "BRANCHNAME". In a series of piped commands, only the return code of the last command is used. Thus, all other commands will have their return codes masked. Avoid piping of output of git directly into sed to preserve the exit status code of "git checkout", while we're here. [1] 05e7368 (checkout: report upstream correctly even with loosely defined branch.*.merge, 2014-10-14) Signed-off-by: Andrei Rybak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 73876f4 commit fd72637

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

t/t2024-checkout-dwim.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,13 @@ test_expect_success 'loosely defined local base branch is reported correctly' '
305305
test_config branch.strict.merge refs/heads/main &&
306306
test_config branch.loose.merge main &&
307307
308-
git checkout strict | sed -e "s/strict/BRANCHNAME/g" >expect &&
308+
git checkout strict >expect.raw 2>&1 &&
309+
sed -e "s/strict/BRANCHNAME/g" <expect.raw >expect &&
309310
status_uno_is_clean &&
310-
git checkout loose | sed -e "s/loose/BRANCHNAME/g" >actual &&
311+
git checkout loose >actual.raw 2>&1 &&
312+
sed -e "s/loose/BRANCHNAME/g" <actual.raw >actual &&
311313
status_uno_is_clean &&
314+
grep BRANCHNAME actual &&
312315
313316
test_cmp expect actual
314317
'

0 commit comments

Comments
 (0)