Skip to content

Commit 986eb34

Browse files
committed
Merge branch 'es/worktree-chatty-to-stderr'
"git worktree add" showed "Preparing worktree" message to the standard output stream, but when it failed, the message from die() went to the standard error stream. Depending on the order the stdio streams are flushed at the program end, this resulted in confusing output. It has been corrected by sending all the chatty messages to the standard error stream. * es/worktree-chatty-to-stderr: git-worktree.txt: add missing `-v` to synopsis for `worktree list` worktree: send "chatty" messages to stderr
2 parents f9b889d + b502524 commit 986eb34

File tree

5 files changed

+28
-34
lines changed

5 files changed

+28
-34
lines changed

Documentation/git-worktree.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SYNOPSIS
1010
--------
1111
[verse]
1212
'git worktree add' [-f] [--detach] [--checkout] [--lock [--reason <string>]] [-b <new-branch>] <path> [<commit-ish>]
13-
'git worktree list' [--porcelain]
13+
'git worktree list' [-v | --porcelain]
1414
'git worktree lock' [--reason <string>] <worktree>
1515
'git worktree move' <worktree> <new-path>
1616
'git worktree prune' [-n] [-v] [--expire <expire>]

builtin/worktree.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static void delete_worktrees_dir_if_empty(void)
7272
static void prune_worktree(const char *id, const char *reason)
7373
{
7474
if (show_only || verbose)
75-
printf_ln(_("Removing %s/%s: %s"), "worktrees", id, reason);
75+
fprintf_ln(stderr, _("Removing %s/%s: %s"), "worktrees", id, reason);
7676
if (!show_only)
7777
delete_git_dir(id);
7878
}
@@ -417,24 +417,24 @@ static void print_preparing_worktree_line(int detach,
417417
if (force_new_branch) {
418418
struct commit *commit = lookup_commit_reference_by_name(new_branch);
419419
if (!commit)
420-
printf_ln(_("Preparing worktree (new branch '%s')"), new_branch);
420+
fprintf_ln(stderr, _("Preparing worktree (new branch '%s')"), new_branch);
421421
else
422-
printf_ln(_("Preparing worktree (resetting branch '%s'; was at %s)"),
422+
fprintf_ln(stderr, _("Preparing worktree (resetting branch '%s'; was at %s)"),
423423
new_branch,
424424
find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV));
425425
} else if (new_branch) {
426-
printf_ln(_("Preparing worktree (new branch '%s')"), new_branch);
426+
fprintf_ln(stderr, _("Preparing worktree (new branch '%s')"), new_branch);
427427
} else {
428428
struct strbuf s = STRBUF_INIT;
429429
if (!detach && !strbuf_check_branch_ref(&s, branch) &&
430430
ref_exists(s.buf))
431-
printf_ln(_("Preparing worktree (checking out '%s')"),
431+
fprintf_ln(stderr, _("Preparing worktree (checking out '%s')"),
432432
branch);
433433
else {
434434
struct commit *commit = lookup_commit_reference_by_name(branch);
435435
if (!commit)
436436
die(_("invalid reference: %s"), branch);
437-
printf_ln(_("Preparing worktree (detached HEAD %s)"),
437+
fprintf_ln(stderr, _("Preparing worktree (detached HEAD %s)"),
438438
find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV));
439439
}
440440
strbuf_release(&s);
@@ -1005,7 +1005,7 @@ static int remove_worktree(int ac, const char **av, const char *prefix)
10051005
static void report_repair(int iserr, const char *path, const char *msg, void *cb_data)
10061006
{
10071007
if (!iserr) {
1008-
printf_ln(_("repair: %s: %s"), msg, path);
1008+
fprintf_ln(stderr, _("repair: %s: %s"), msg, path);
10091009
} else {
10101010
int *exit_status = (int *)cb_data;
10111011
fprintf_ln(stderr, _("error: %s: %s"), msg, path);

t/t2401-worktree-prune.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test_expect_success 'worktree prune on normal repo' '
1919
test_expect_success 'prune files inside $GIT_DIR/worktrees' '
2020
mkdir .git/worktrees &&
2121
: >.git/worktrees/abc &&
22-
git worktree prune --verbose >actual &&
22+
git worktree prune --verbose 2>actual &&
2323
cat >expect <<EOF &&
2424
Removing worktrees/abc: not a valid directory
2525
EOF
@@ -34,7 +34,7 @@ test_expect_success 'prune directories without gitdir' '
3434
cat >expect <<EOF &&
3535
Removing worktrees/def: gitdir file does not exist
3636
EOF
37-
git worktree prune --verbose >actual &&
37+
git worktree prune --verbose 2>actual &&
3838
test_cmp expect actual &&
3939
! test -d .git/worktrees/def &&
4040
! test -d .git/worktrees
@@ -45,7 +45,7 @@ test_expect_success SANITY 'prune directories with unreadable gitdir' '
4545
: >.git/worktrees/def/def &&
4646
: >.git/worktrees/def/gitdir &&
4747
chmod u-r .git/worktrees/def/gitdir &&
48-
git worktree prune --verbose >actual &&
48+
git worktree prune --verbose 2>actual &&
4949
test_i18ngrep "Removing worktrees/def: unable to read gitdir file" actual &&
5050
! test -d .git/worktrees/def &&
5151
! test -d .git/worktrees
@@ -55,7 +55,7 @@ test_expect_success 'prune directories with invalid gitdir' '
5555
mkdir -p .git/worktrees/def/abc &&
5656
: >.git/worktrees/def/def &&
5757
: >.git/worktrees/def/gitdir &&
58-
git worktree prune --verbose >actual &&
58+
git worktree prune --verbose 2>actual &&
5959
test_i18ngrep "Removing worktrees/def: invalid gitdir file" actual &&
6060
! test -d .git/worktrees/def &&
6161
! test -d .git/worktrees
@@ -65,7 +65,7 @@ test_expect_success 'prune directories with gitdir pointing to nowhere' '
6565
mkdir -p .git/worktrees/def/abc &&
6666
: >.git/worktrees/def/def &&
6767
echo "$(pwd)"/nowhere >.git/worktrees/def/gitdir &&
68-
git worktree prune --verbose >actual &&
68+
git worktree prune --verbose 2>actual &&
6969
test_i18ngrep "Removing worktrees/def: gitdir file points to non-existent location" actual &&
7070
! test -d .git/worktrees/def &&
7171
! test -d .git/worktrees
@@ -101,7 +101,7 @@ test_expect_success 'prune duplicate (linked/linked)' '
101101
git worktree add --detach w2 &&
102102
sed "s/w2/w1/" .git/worktrees/w2/gitdir >.git/worktrees/w2/gitdir.new &&
103103
mv .git/worktrees/w2/gitdir.new .git/worktrees/w2/gitdir &&
104-
git worktree prune --verbose >actual &&
104+
git worktree prune --verbose 2>actual &&
105105
test_i18ngrep "duplicate entry" actual &&
106106
test -d .git/worktrees/w1 &&
107107
! test -d .git/worktrees/w2
@@ -114,7 +114,7 @@ test_expect_success 'prune duplicate (main/linked)' '
114114
git -C repo worktree add --detach ../wt &&
115115
rm -fr wt &&
116116
mv repo wt &&
117-
git -C wt worktree prune --verbose >actual &&
117+
git -C wt worktree prune --verbose 2>actual &&
118118
test_i18ngrep "duplicate entry" actual &&
119119
! test -d .git/worktrees/wt
120120
'

t/t2402-worktree-list.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ test_expect_success '"list" all worktrees with prunable consistent with "prune"'
134134
git worktree list >out &&
135135
grep "/prunable *[0-9a-f].* prunable$" out &&
136136
! grep "/unprunable *[0-9a-f].* unprunable$" out &&
137-
git worktree prune --verbose >out &&
137+
git worktree prune --verbose 2>out &&
138138
test_i18ngrep "^Removing worktrees/prunable" out &&
139139
test_i18ngrep ! "^Removing worktrees/unprunable" out
140140
'

t/t2406-worktree-repair.sh

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ test_corrupt_gitfile () {
4545
git worktree add --detach corrupt &&
4646
git -C corrupt rev-parse --absolute-git-dir >expect &&
4747
eval "$butcher" &&
48-
git -C "$repairdir" worktree repair >out 2>err &&
49-
test_i18ngrep "$problem" out &&
50-
test_must_be_empty err &&
48+
git -C "$repairdir" worktree repair 2>err &&
49+
test_i18ngrep "$problem" err &&
5150
git -C corrupt rev-parse --absolute-git-dir >actual &&
5251
test_cmp expect actual
5352
}
@@ -130,42 +129,38 @@ test_expect_success 'repair broken gitdir' '
130129
sed s,orig/\.git$,moved/.git, .git/worktrees/orig/gitdir >expect &&
131130
rm .git/worktrees/orig/gitdir &&
132131
mv orig moved &&
133-
git worktree repair moved >out 2>err &&
132+
git worktree repair moved 2>err &&
134133
test_cmp expect .git/worktrees/orig/gitdir &&
135-
test_i18ngrep "gitdir unreadable" out &&
136-
test_must_be_empty err
134+
test_i18ngrep "gitdir unreadable" err
137135
'
138136

139137
test_expect_success 'repair incorrect gitdir' '
140138
test_when_finished "rm -rf orig moved && git worktree prune" &&
141139
git worktree add --detach orig &&
142140
sed s,orig/\.git$,moved/.git, .git/worktrees/orig/gitdir >expect &&
143141
mv orig moved &&
144-
git worktree repair moved >out 2>err &&
142+
git worktree repair moved 2>err &&
145143
test_cmp expect .git/worktrees/orig/gitdir &&
146-
test_i18ngrep "gitdir incorrect" out &&
147-
test_must_be_empty err
144+
test_i18ngrep "gitdir incorrect" err
148145
'
149146

150147
test_expect_success 'repair gitdir (implicit) from linked worktree' '
151148
test_when_finished "rm -rf orig moved && git worktree prune" &&
152149
git worktree add --detach orig &&
153150
sed s,orig/\.git$,moved/.git, .git/worktrees/orig/gitdir >expect &&
154151
mv orig moved &&
155-
git -C moved worktree repair >out 2>err &&
152+
git -C moved worktree repair 2>err &&
156153
test_cmp expect .git/worktrees/orig/gitdir &&
157-
test_i18ngrep "gitdir incorrect" out &&
158-
test_must_be_empty err
154+
test_i18ngrep "gitdir incorrect" err
159155
'
160156

161157
test_expect_success 'unable to repair gitdir (implicit) from main worktree' '
162158
test_when_finished "rm -rf orig moved && git worktree prune" &&
163159
git worktree add --detach orig &&
164160
cat .git/worktrees/orig/gitdir >expect &&
165161
mv orig moved &&
166-
git worktree repair >out 2>err &&
162+
git worktree repair 2>err &&
167163
test_cmp expect .git/worktrees/orig/gitdir &&
168-
test_must_be_empty out &&
169164
test_must_be_empty err
170165
'
171166

@@ -178,12 +173,11 @@ test_expect_success 'repair multiple gitdir files' '
178173
sed s,orig2/\.git$,moved2/.git, .git/worktrees/orig2/gitdir >expect2 &&
179174
mv orig1 moved1 &&
180175
mv orig2 moved2 &&
181-
git worktree repair moved1 moved2 >out 2>err &&
176+
git worktree repair moved1 moved2 2>err &&
182177
test_cmp expect1 .git/worktrees/orig1/gitdir &&
183178
test_cmp expect2 .git/worktrees/orig2/gitdir &&
184-
test_i18ngrep "gitdir incorrect:.*orig1/gitdir$" out &&
185-
test_i18ngrep "gitdir incorrect:.*orig2/gitdir$" out &&
186-
test_must_be_empty err
179+
test_i18ngrep "gitdir incorrect:.*orig1/gitdir$" err &&
180+
test_i18ngrep "gitdir incorrect:.*orig2/gitdir$" err
187181
'
188182

189183
test_expect_success 'repair moved main and linked worktrees' '

0 commit comments

Comments
 (0)