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
This commit is contained in:
Junio C Hamano 2021-12-15 09:39:49 -08:00
commit 986eb34b71
5 changed files with 28 additions and 34 deletions

View file

@ -10,7 +10,7 @@ SYNOPSIS
--------
[verse]
'git worktree add' [-f] [--detach] [--checkout] [--lock [--reason <string>]] [-b <new-branch>] <path> [<commit-ish>]
'git worktree list' [--porcelain]
'git worktree list' [-v | --porcelain]
'git worktree lock' [--reason <string>] <worktree>
'git worktree move' <worktree> <new-path>
'git worktree prune' [-n] [-v] [--expire <expire>]

View file

@ -72,7 +72,7 @@ static void delete_worktrees_dir_if_empty(void)
static void prune_worktree(const char *id, const char *reason)
{
if (show_only || verbose)
printf_ln(_("Removing %s/%s: %s"), "worktrees", id, reason);
fprintf_ln(stderr, _("Removing %s/%s: %s"), "worktrees", id, reason);
if (!show_only)
delete_git_dir(id);
}
@ -417,24 +417,24 @@ static void print_preparing_worktree_line(int detach,
if (force_new_branch) {
struct commit *commit = lookup_commit_reference_by_name(new_branch);
if (!commit)
printf_ln(_("Preparing worktree (new branch '%s')"), new_branch);
fprintf_ln(stderr, _("Preparing worktree (new branch '%s')"), new_branch);
else
printf_ln(_("Preparing worktree (resetting branch '%s'; was at %s)"),
fprintf_ln(stderr, _("Preparing worktree (resetting branch '%s'; was at %s)"),
new_branch,
find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV));
} else if (new_branch) {
printf_ln(_("Preparing worktree (new branch '%s')"), new_branch);
fprintf_ln(stderr, _("Preparing worktree (new branch '%s')"), new_branch);
} else {
struct strbuf s = STRBUF_INIT;
if (!detach && !strbuf_check_branch_ref(&s, branch) &&
ref_exists(s.buf))
printf_ln(_("Preparing worktree (checking out '%s')"),
fprintf_ln(stderr, _("Preparing worktree (checking out '%s')"),
branch);
else {
struct commit *commit = lookup_commit_reference_by_name(branch);
if (!commit)
die(_("invalid reference: %s"), branch);
printf_ln(_("Preparing worktree (detached HEAD %s)"),
fprintf_ln(stderr, _("Preparing worktree (detached HEAD %s)"),
find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV));
}
strbuf_release(&s);
@ -1005,7 +1005,7 @@ static int remove_worktree(int ac, const char **av, const char *prefix)
static void report_repair(int iserr, const char *path, const char *msg, void *cb_data)
{
if (!iserr) {
printf_ln(_("repair: %s: %s"), msg, path);
fprintf_ln(stderr, _("repair: %s: %s"), msg, path);
} else {
int *exit_status = (int *)cb_data;
fprintf_ln(stderr, _("error: %s: %s"), msg, path);

View file

@ -19,7 +19,7 @@ test_expect_success 'worktree prune on normal repo' '
test_expect_success 'prune files inside $GIT_DIR/worktrees' '
mkdir .git/worktrees &&
: >.git/worktrees/abc &&
git worktree prune --verbose >actual &&
git worktree prune --verbose 2>actual &&
cat >expect <<EOF &&
Removing worktrees/abc: not a valid directory
EOF
@ -34,7 +34,7 @@ test_expect_success 'prune directories without gitdir' '
cat >expect <<EOF &&
Removing worktrees/def: gitdir file does not exist
EOF
git worktree prune --verbose >actual &&
git worktree prune --verbose 2>actual &&
test_cmp expect actual &&
! test -d .git/worktrees/def &&
! test -d .git/worktrees
@ -45,7 +45,7 @@ test_expect_success SANITY 'prune directories with unreadable gitdir' '
: >.git/worktrees/def/def &&
: >.git/worktrees/def/gitdir &&
chmod u-r .git/worktrees/def/gitdir &&
git worktree prune --verbose >actual &&
git worktree prune --verbose 2>actual &&
test_i18ngrep "Removing worktrees/def: unable to read gitdir file" actual &&
! test -d .git/worktrees/def &&
! test -d .git/worktrees
@ -55,7 +55,7 @@ test_expect_success 'prune directories with invalid gitdir' '
mkdir -p .git/worktrees/def/abc &&
: >.git/worktrees/def/def &&
: >.git/worktrees/def/gitdir &&
git worktree prune --verbose >actual &&
git worktree prune --verbose 2>actual &&
test_i18ngrep "Removing worktrees/def: invalid gitdir file" actual &&
! test -d .git/worktrees/def &&
! test -d .git/worktrees
@ -65,7 +65,7 @@ test_expect_success 'prune directories with gitdir pointing to nowhere' '
mkdir -p .git/worktrees/def/abc &&
: >.git/worktrees/def/def &&
echo "$(pwd)"/nowhere >.git/worktrees/def/gitdir &&
git worktree prune --verbose >actual &&
git worktree prune --verbose 2>actual &&
test_i18ngrep "Removing worktrees/def: gitdir file points to non-existent location" actual &&
! test -d .git/worktrees/def &&
! test -d .git/worktrees
@ -101,7 +101,7 @@ test_expect_success 'prune duplicate (linked/linked)' '
git worktree add --detach w2 &&
sed "s/w2/w1/" .git/worktrees/w2/gitdir >.git/worktrees/w2/gitdir.new &&
mv .git/worktrees/w2/gitdir.new .git/worktrees/w2/gitdir &&
git worktree prune --verbose >actual &&
git worktree prune --verbose 2>actual &&
test_i18ngrep "duplicate entry" actual &&
test -d .git/worktrees/w1 &&
! test -d .git/worktrees/w2
@ -114,7 +114,7 @@ test_expect_success 'prune duplicate (main/linked)' '
git -C repo worktree add --detach ../wt &&
rm -fr wt &&
mv repo wt &&
git -C wt worktree prune --verbose >actual &&
git -C wt worktree prune --verbose 2>actual &&
test_i18ngrep "duplicate entry" actual &&
! test -d .git/worktrees/wt
'

View file

@ -134,7 +134,7 @@ test_expect_success '"list" all worktrees with prunable consistent with "prune"'
git worktree list >out &&
grep "/prunable *[0-9a-f].* prunable$" out &&
! grep "/unprunable *[0-9a-f].* unprunable$" out &&
git worktree prune --verbose >out &&
git worktree prune --verbose 2>out &&
test_i18ngrep "^Removing worktrees/prunable" out &&
test_i18ngrep ! "^Removing worktrees/unprunable" out
'

View file

@ -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' '