Skip to contentSkip to conversation

worktree remove: clarify error message on dirty worktree

PATCH In review SZEDER Gábor 3 participants 3 messages Aug 13, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 worktree remove: clarify error message on dirty worktree

To avoid data loss, 'git worktree remove' refuses to delete a worktree if it's dirty or contains untracked files. However, the error message only mentions that the worktree "is dirty", even if the worktree in question is in fact clean, but contains untracked files:

  $ git worktree add test-worktree
  Preparing worktree (new branch 'test-worktree')
  HEAD is now at aa53e60 Initial
  $ >test-worktree/untracked-file
  $ git worktree remove test-worktree/
  fatal: 'test-worktree/' is dirty, use --force to delete it
  $ git -C test-worktree/ diff
  $ git -C test-worktree/ diff --cached
  $ # Huh?  Where are those dirty files?!

Clarify this error message to say that the worktree "contains modified or untracked files".

---

I spent more time searching for those dirty files that I would like to admit...

 builtin/worktree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/worktree.c +1 -1
index a5bb02b207..7f094f8170 100644
@@ -880,7 +880,7 @@ static void check_clean_worktree(struct worktree *wt,
 			  original_path);
 	ret = xread(cp.out, buf, sizeof(buf));
 	if (ret)
-		die(_("'%s' is dirty, use --force to delete it"),
+		die(_("'%s' contains modified or untracked files, use --force to delete it"),
 		    original_path);
 	close(cp.out);
 	ret = finish_command(&cp);
Signature · 1 line
2.23.0.rc2.350.gf4fdc32db7
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · SZEDER Gábor

To avoid data loss, 'git worktree remove' refuses to delete a worktree if it's dirty or contains untracked files. However, the error message only mentions that the worktree "is dirty", even if the worktree in question is in fact clean, but contains untracked files:
[...]
Clarify this error message to say that the worktree "contains modified or untracked files".

---

builtin/worktree.c static void check_clean_worktree(struct worktree *wt, · line 883

Quoted 5 lines
builtin/worktree.c +1 -1
@@ -880,7 +880,7 @@ static void check_clean_worktree(struct worktree *wt,
        ret = xread(cp.out, buf, sizeof(buf));
        if (ret)
-               die(_("'%s' is dirty, use --force to delete it"),
+               die(_("'%s' contains modified or untracked files, use --force to delete it"),
                    original_path);

Makes sense. This is a different type of "dirtiness" than, say, "git rebase --interactive" which cares about unstaged changes but generally doesn't mind untracked files. So, it deserves an error message which mentions untracked files explicitly.

We could actually parse the output of "git status --porcelain" (which is invoked just above this spot) and provide a more specific error message ("...contains modified files" or "...contains untracked files") but that's probably not worth the effort.

Anyhow, for what it's worth:

#2 lore raw
Quoted 24 lines · Eric Sunshine
Quoted 12 lines · SZEDER Gábor

To avoid data loss, 'git worktree remove' refuses to delete a worktree if it's dirty or contains untracked files. However, the error message only mentions that the worktree "is dirty", even if the worktree in question is in fact clean, but contains untracked files:
[...]
Clarify this error message to say that the worktree "contains modified or untracked files".

---

builtin/worktree.c static void check_clean_worktree(struct worktree *wt, · line 883

Quoted 5 lines
builtin/worktree.c +1 -1
@@ -880,7 +880,7 @@ static void check_clean_worktree(struct worktree *wt,
        ret = xread(cp.out, buf, sizeof(buf));
        if (ret)
-               die(_("'%s' is dirty, use --force to delete it"),
+               die(_("'%s' contains modified or untracked files, use --force to delete it"),
                    original_path);

Makes sense. This is a different type of "dirtiness" than, say, "git rebase --interactive" which cares about unstaged changes but generally doesn't mind untracked files. So, it deserves an error message which mentions untracked files explicitly.

Quoted 7 lines

We could actually parse the output of "git status --porcelain" (which is invoked just above this spot) and provide a more specific error message ("...contains modified files" or "...contains untracked files") but that's probably not worth the effort.

Anyhow, for what it's worth:

Thanks, both.