[RFC] status - don't show gitdir

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Fredrik Gustafsson <iveqy@xxxxxxxxx>
---
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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]