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

[RFC] status - don't show gitdir

From
Fredrik Gustafsson <iveqy@iveqy.com>
Date
Jun 30, 2011, 11:46 UTC
Message-ID
<1309434388-3536-1-git-send-email-iveqy@iveqy.com>
In-Reply-To
<4E0C3C1D.1050406@nextest.com>

When gitdir is inside the working dir, don't show it as a untracked directory.

Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>
---
This patch works but have a few weaknesses. The string manipulations done
is cumbersome and can possible be done nicer (not what I could to with
support of strbuf).

Also, this patch doesn't know why .git isn't showed as untracked. Maybe this code is at the wrong place.

 dir.c             |   28 ++++++++++++++++++++++++++++
 t/t7508-status.sh |   10 ++++++++++
 2 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/dir.c b/dir.c
index 08281d2..9cabc29 100644
--- a/dir.c
+++ b/dir.c
@@ -1215,6 +1215,13 @@ int remove_dir_recursively(struct strbuf *path, int flag)
 void setup_standard_excludes(struct dir_struct *dir)
 {
 	const char *path;
+	const char *work_tree;
+	const char *git_dir;
+	struct strbuf wt_full;
+	struct strbuf gd_base;
+	struct strbuf gd_relpath;
+	struct strbuf gd;
+	int i = 0;
 
 	dir->exclude_per_dir = ".gitignore";
 	path = git_path("info/exclude");
@@ -1222,6 +1229,27 @@ void setup_standard_excludes(struct dir_struct *dir)
 		add_excludes_from_file(dir, path);
 	if (excludes_file && !access(excludes_file, R_OK))
 		add_excludes_from_file(dir, excludes_file);
+	work_tree = get_git_work_tree();
+	strbuf_init(&wt_full,0);
+	strbuf_addstr(&wt_full,work_tree);
+	strbuf_addstr(&wt_full,"/.git");
+	git_dir = read_gitfile_gently(wt_full.buf);
+	strbuf_remove(&wt_full,wt_full.len-5,5);
+	if(git_dir) {
+		strbuf_init(&gd,0);
+		strbuf_addstr(&gd,git_dir);
+		if(gd.len > wt_full.len) {
+			strbuf_init(&gd_base,0);
+			strbuf_add(&gd_base,wt_full.buf,wt_full.len);
+			if(!strbuf_cmp(&gd_base,&wt_full)) {
+				strbuf_init(&gd_relpath,0);
+				for(i = gd_base.len + 1; i < gd.len; i++) {
+					strbuf_addch(&gd_relpath,gd.buf[i]);
+				}
+				add_exclude(gd_relpath.buf,"",0,&dir->exclude_list[EXC_FILE]);
+			}
+		}
+	}
 }
 
 int remove_path(const char *name)
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index 1fdfbd3..1fed0cf 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -1139,4 +1139,14 @@ test_expect_failure '.git/config ignore=all suppresses submodule summary' '
 	git config -f .gitmodules  --remove-section submodule.subname
 '
 
+test_expect_success 'Check if git-dir is ignored when gitfile is used' '
+	git init gitdir-test &&
+	cd gitdir-test &&
+	mv .git real-git-dir &&
+	echo "gitdir: real-git-dir" > .git &&
+	git status -s real-git-dir > actual &&
+	> expect &&
+	test_cmp actual expect
+'
+
 test_done
-- 
1.7.6.rc3.dirty
Previous: Eric RaibleNext: Nguyen Thai Ngoc Duy
Message 2 of 5 in “Should 'git status' understand a .git containing "gitdir: dir"?”
  1. Eric RaibleJun 30, 2011
  2. [RFC] status - don't show gitdirFredrik Gustafsson, Jun 30, 2011
  3. Nguyen Thai Ngoc DuyJun 30, 2011
  4. Junio C HamanoJun 30, 2011
  5. Eric RaibleJun 30, 2011

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.