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

Re: [BUG] git status doesn't handle submodules properly on OSX

From
Jeff King <peff@peff.net>
Date
Oct 16, 2008, 14:18 UTC
Message-ID
<20081016141812.GA30026@sigill.intra.peff.net>
In-Reply-To
<8199b7ae4c441c4311045141ddaaa36f.squirrel@webmail.highteq.net>
On Thu, Oct 16, 2008 at 02:30:00PM +0200, Lars Hoss wrote:
Show 6 quoted lines
> The commit was on Jun 5, 14:47:50 by Marius Storm-Olsen and the relevant
> file is wt-status.c.
> 
> Ok, I think I found the issue. I enabled showUntrackedFiles in my gitconfig:
> 
> status.showUntrackedFiles = all

Ah, OK. I see what is going on. All code paths call the read_directory infrastructure to find untracked files. If status.showUntrackedFiles is "normal", then we set dir.show_other_directories, to indicate that we want to see the directories, but not their constituent files.

If status.showuntrackedfiles is set to "all", then we don't set the show_other_directories flag, because we want each file. But the code in dir.c:treat_directory uses the "show_other_directories" flag to say "oh, we're just interested in untracked files" and decide whether to ignore gitlinks.

Meaning that we must still filter the results of read_directory based on the cache. And indeed, this is what "git ls-files -o" does, as explained in 5698454e (Fix some "git ls-files -o" fallout from gitlinks). It's also what the code in wt_status_print_untracked is _supposed_ to do, but it was never updated to handle this case when git-ls-files was. Which is probably my fault a long time ago for cutting and pasting the 5 lines of "is this thing in the cache" when writing wt-status.c.

So the quick fix is to re-cut-and-paste the code:
diff --git a/wt-status.c b/wt-status.c
index d2eac36..792d5f1 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -280,10 +280,14 @@ static void wt_status_print_untracked(struct wt_status *s)
 		/* check for matching entry, which is unmerged; lifted from
 		 * builtin-ls-files:show_other_files */
 		struct dir_entry *ent = dir.entries[i];
-		int pos = cache_name_pos(ent->name, ent->len);
+		int len, pos;
+		len = ent->len;
+		if (len && ent->name[len-1] == '/')
+			len--;
+		pos = cache_name_pos(ent->name, len);
 		struct cache_entry *ce;
 		if (0 <= pos)
-			die("bug in wt_status_print_untracked");
+			continue;
 		pos = -pos - 1;
 		if (pos < active_nr) {
 			ce = active_cache[pos];

But the right solution is to refactor this so the code isn't duplicated.
And I'll post a patch for that in a second.

I do have to wonder, though, whether an even better solution would be to
more explicitly tell read_directory "I'm interested only in 'other'
files" rather than relying on guessing based on
dir.show_other_directories. Then we could just avoid ever passing these
gitlinks back to ls-files and status in the first place.

-Peff
Previous: Lars HossNext: Jeff King
Message 17 of 21 in “[BUG] git status doesn't handle submodules properly on OSX”
  1. Lars HossOct 15, 2008
  2. Jeff KingOct 15, 2008
  3. Lars HossOct 15, 2008
  4. Pieter de BieOct 15, 2008
  5. Lars HossOct 15, 2008
  6. Pieter de BieOct 15, 2008
  7. Lars HossOct 15, 2008
  8. Richard BubelOct 15, 2008
  9. Lars HossOct 15, 2008
  10. Pedro MeloOct 16, 2008
  11. Pedro MeloOct 16, 2008
  12. Lars HossOct 16, 2008
  13. Lars HossOct 16, 2008
  14. Johannes SixtOct 16, 2008
  15. Lars HossOct 16, 2008
  16. Lars HossOct 16, 2008
  17. Jeff KingOct 16, 2008
  18. refactor handling of "other" files in ls-files and statusJeff King, Oct 16, 2008
  19. Jeff KingOct 16, 2008
  20. Junio C HamanoOct 17, 2008
  21. Pedro MeloOct 16, 2008

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.