git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH] status: avoid reporting worktrees as "Untracked files"

From
Edmundo Carmona Antoranz <eantoranz@gmail.com>
Date
Nov 4, 2023, 00:02 UTC
Message-ID
<20231104000209.916189-1-eantoranz@gmail.com>

Given that worktrees are tracked in their own special fashion separately, it makes sense to _not_ report them as "untracked". Also, when seeing the directory of a worktree listed as Untracked, it might be tempting to try to do operations (like 'git add') on them from the parent worktree which, at the moment, will silently do nothing.

With this patch, we check items against the list of worktrees to add them into the untracked items list effectively hiding them.

END OF PATCH
Here are a few questions more inline with the "RFC" part of the patch.
About UI
- Would it make more sense to separate them from Untracked files instead
  of hiding them (perhaps add a --worktrees option to display them)?
- Follow-up if the previous answer is 'yes': List a worktree only if it
  is not clean?
About code:
- If keeping the idea/patch, Would it make more sense (performance-wise) to
  fist check an item in the list of worktrees before checking it in the
  index? In other words, reverse the conditions to add an item to the
  untracked list?
---
 wt-status.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/wt-status.c b/wt-status.c
index 9f45bf6949..5fd1e6007a 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -775,6 +775,7 @@ static void wt_status_collect_untracked(struct wt_status *s)
 	struct dir_struct dir = DIR_INIT;
 	uint64_t t_begin = getnanotime();
 	struct index_state *istate = s->repo->index;
+	struct worktree **worktrees;
 
 	if (!s->show_untracked_files)
 		return;
@@ -795,9 +796,12 @@ static void wt_status_collect_untracked(struct wt_status *s)
 
 	fill_directory(&dir, istate, &s->pathspec);
 
+	worktrees = get_worktrees();
+
 	for (i = 0; i < dir.nr; i++) {
 		struct dir_entry *ent = dir.entries[i];
-		if (index_name_is_other(istate, ent->name, ent->len))
+		if (index_name_is_other(istate, ent->name, ent->len) &&
+		    !find_worktree_by_path(worktrees, ent->name))
 			string_list_insert(&s->untracked, ent->name);
 	}
 
@@ -809,6 +813,9 @@ static void wt_status_collect_untracked(struct wt_status *s)
 
 	dir_clear(&dir);
 
+	if (worktrees)
+		free_worktrees(worktrees);
+
 	if (advice_enabled(ADVICE_STATUS_U_OPTION))
 		s->untracked_in_ms = (getnanotime() - t_begin) / 1000000;
 }
-- 
2.42.0
Next: Eric Sunshine
Message 1 of 6 in “status: avoid reporting worktrees as "Untracked files"”
  1. status: avoid reporting worktrees as "Untracked files"Edmundo Carmona Antoranz, Nov 4, 2023
  2. Eric SunshineNov 4, 2023
  3. Junio C HamanoNov 4, 2023
  4. Edmundo Carmona AntoranzNov 11, 2023
  5. Eric SunshineNov 12, 2023
  6. Junio C HamanoNov 12, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.