summaryrefslogtreecommitdiff
path: root/t/t2406-worktree-repair.sh
diff options
context:
space:
mode:
authorEric Sunshine <sunshine@sunshineco.com>2021-12-03 03:44:19 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-12-05 07:27:11 (GMT)
commitda8fb6be5594b4a06ef2cc2ff7a5363a6fac2b5a (patch)
treeeda67c8313e9cf071efe3c6172b0524e44d0e35b /t/t2406-worktree-repair.sh
parente9d7761bb94f20acc98824275e317fa82436c25d (diff)
downloadgit-da8fb6be5594b4a06ef2cc2ff7a5363a6fac2b5a.zip
git-da8fb6be5594b4a06ef2cc2ff7a5363a6fac2b5a.tar.gz
git-da8fb6be5594b4a06ef2cc2ff7a5363a6fac2b5a.tar.bz2
worktree: send "chatty" messages to stderr
The order in which the stdout and stderr streams are flushed is not guaranteed to be the same across platforms or `libc` implementations. This lack of determinism can lead to anomalous and potentially confusing output if normal (stdout) output is flushed after error (stderr) output. For instance, the following output which clearly indicates a failure due to a fatal error: % git worktree add ../foo bar Preparing worktree (checking out 'bar') fatal: 'bar' is already checked out at '.../wherever' has been reported[1] on Microsoft Windows to appear as: % git worktree add ../foo bar fatal: 'bar' is already checked out at '.../wherever' Preparing worktree (checking out 'bar') which may confuse the reader into thinking that the command somehow recovered and ran to completion despite the error. This problem crops up because the "chatty" status message "Preparing worktree" is sent to stdout, whereas the "fatal" error message is sent to stderr. One way to fix this would be to flush stdout manually before git-worktree reports any errors to stderr. However, common practice in Git is for "chatty" messages to be sent to stderr. Therefore, a more appropriate fix is to adjust git-worktree to conform to that practice by sending its "chatty" messages to stderr rather than stdout as is currently the case. There may be concern that relocating messages from stdout to stderr could break existing tooling, however, these messages are already internationalized, thus are unstable. And, indeed, the "Preparing worktree" message has already been the subject of somewhat significant changes in 2c27002a0a (worktree: improve message when creating a new worktree, 2018-04-24). Moreover, there is existing precedent, such as 68b939b2f0 (clone: send diagnostic messages to stderr, 2013-09-18) which likewise relocated "chatty" messages from stdout to stderr for git-clone. [1]: https://lore.kernel.org/git/CA+34VNLj6VB1kCkA=MfM7TZR+6HgqNi5-UaziAoCXacSVkch4A@mail.gmail.com/T/ Reported-by: Baruch Burstein <bmburstein@gmail.com> Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t2406-worktree-repair.sh')
-rwxr-xr-xt/t2406-worktree-repair.sh30
1 files changed, 12 insertions, 18 deletions
diff --git a/t/t2406-worktree-repair.sh b/t/t2406-worktree-repair.sh
index f737418..5c44453 100755
--- a/t/t2406-worktree-repair.sh
+++ b/t/t2406-worktree-repair.sh
@@ -45,9 +45,8 @@ test_corrupt_gitfile () {
git worktree add --detach corrupt &&
git -C corrupt rev-parse --absolute-git-dir >expect &&
eval "$butcher" &&
- git -C "$repairdir" worktree repair >out 2>err &&
- test_i18ngrep "$problem" out &&
- test_must_be_empty err &&
+ git -C "$repairdir" worktree repair 2>err &&
+ test_i18ngrep "$problem" err &&
git -C corrupt rev-parse --absolute-git-dir >actual &&
test_cmp expect actual
}
@@ -130,10 +129,9 @@ test_expect_success 'repair broken gitdir' '
sed s,orig/\.git$,moved/.git, .git/worktrees/orig/gitdir >expect &&
rm .git/worktrees/orig/gitdir &&
mv orig moved &&
- git worktree repair moved >out 2>err &&
+ git worktree repair moved 2>err &&
test_cmp expect .git/worktrees/orig/gitdir &&
- test_i18ngrep "gitdir unreadable" out &&
- test_must_be_empty err
+ test_i18ngrep "gitdir unreadable" err
'
test_expect_success 'repair incorrect gitdir' '
@@ -141,10 +139,9 @@ test_expect_success 'repair incorrect gitdir' '
git worktree add --detach orig &&
sed s,orig/\.git$,moved/.git, .git/worktrees/orig/gitdir >expect &&
mv orig moved &&
- git worktree repair moved >out 2>err &&
+ git worktree repair moved 2>err &&
test_cmp expect .git/worktrees/orig/gitdir &&
- test_i18ngrep "gitdir incorrect" out &&
- test_must_be_empty err
+ test_i18ngrep "gitdir incorrect" err
'
test_expect_success 'repair gitdir (implicit) from linked worktree' '
@@ -152,10 +149,9 @@ test_expect_success 'repair gitdir (implicit) from linked worktree' '
git worktree add --detach orig &&
sed s,orig/\.git$,moved/.git, .git/worktrees/orig/gitdir >expect &&
mv orig moved &&
- git -C moved worktree repair >out 2>err &&
+ git -C moved worktree repair 2>err &&
test_cmp expect .git/worktrees/orig/gitdir &&
- test_i18ngrep "gitdir incorrect" out &&
- test_must_be_empty err
+ test_i18ngrep "gitdir incorrect" err
'
test_expect_success 'unable to repair gitdir (implicit) from main worktree' '
@@ -163,9 +159,8 @@ test_expect_success 'unable to repair gitdir (implicit) from main worktree' '
git worktree add --detach orig &&
cat .git/worktrees/orig/gitdir >expect &&
mv orig moved &&
- git worktree repair >out 2>err &&
+ git worktree repair 2>err &&
test_cmp expect .git/worktrees/orig/gitdir &&
- test_must_be_empty out &&
test_must_be_empty err
'
@@ -178,12 +173,11 @@ test_expect_success 'repair multiple gitdir files' '
sed s,orig2/\.git$,moved2/.git, .git/worktrees/orig2/gitdir >expect2 &&
mv orig1 moved1 &&
mv orig2 moved2 &&
- git worktree repair moved1 moved2 >out 2>err &&
+ git worktree repair moved1 moved2 2>err &&
test_cmp expect1 .git/worktrees/orig1/gitdir &&
test_cmp expect2 .git/worktrees/orig2/gitdir &&
- test_i18ngrep "gitdir incorrect:.*orig1/gitdir$" out &&
- test_i18ngrep "gitdir incorrect:.*orig2/gitdir$" out &&
- test_must_be_empty err
+ test_i18ngrep "gitdir incorrect:.*orig1/gitdir$" err &&
+ test_i18ngrep "gitdir incorrect:.*orig2/gitdir$" err
'
test_expect_success 'repair moved main and linked worktrees' '