Should 'git status' understand a .git containing "gitdir: dir"?
The following sequence sets up a trivial repo that uses "gitdir:":
$ git init gitdir-test $ cd gitdir-test $ mv .git real-git-dir $ echo "gitdir: real-git-dir" > .git $ git status
Fine so far. But git-status shows that "real-git-dir" is untracked:
$ git status -sb ## Initial commit on master ?? real-git-dir/
Which strikes one as a bit inconsistent (since other pars of git-status knows to look in real-git-dir to find the index).
Sorry - no time to investigate.
RFC 1/1 status - don't show gitdir
When gitdir is inside the working dir, don't show it as a untracked directory.
---
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(-)
dir.c +28 -0
@@ -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)
t/t7508-status.sh +10 -0
@@ -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
Signature · 1 line
1.7.6.rc3.dirty
Re: [RFC] status - don't show gitdir
Quoted 2 lines · Fredrik Gustafsson
When gitdir is inside the working dir, don't show it as a untracked directory.
read_directory_recursive() and friends ignore .git by default. I think if you want to ignore the directory that .git file points to, you should update there. I'm too lazy to check the code (my read_directory_recursive is heavily modified currently), but I think it does not check file type for .git entries now.
But if we step back a bit, why do you want git to automatically ignore dirs that .git file points to? .git files are used to save real repo somewhere safe, e.g. outside working directory. You do not handle another case in your patch, where .git is a real symlink. In both cases, it's not hard to add "real-git-dir" to .git/info/excludes.
Signature · 1 line
Duy
Quoted 10 lines · Eric Raible
The following sequence sets up a trivial repo that uses "gitdir:":
$ git init gitdir-test $ cd gitdir-test $ mv .git real-git-dir $ echo "gitdir: real-git-dir" > .git $ git statusFine so far. But git-status shows that "real-git-dir" is untracked:
Quoted 8 lines
$ git status -sb ## Initial commit on master ?? real-git-dir/Which strikes one as a bit inconsistent (since other pars of git-status knows to look in real-git-dir to find the index).
Sorry - no time to investigate.
You could even have a real git dir of some completely unrelated repository in your working tree, it will get reported as untracked, and you would probably not want to track its contents, either (or you might want to if you are trying to be funny, I dunno).
So I do not see there is anything to investigate. What you observed looks perfectly expected to me, except for the "mv .git real-git-dir" bit that makes a situation that confuses yourself (but not git).
Quoted 26 lines · Junio C Hamano
Quoted 10 lines · Eric Raible
The following sequence sets up a trivial repo that uses "gitdir:":
$ git init gitdir-test $ cd gitdir-test $ mv .git real-git-dir $ echo "gitdir: real-git-dir" > .git $ git statusFine so far. But git-status shows that "real-git-dir" is untracked:
Quoted 8 lines
$ git status -sb ## Initial commit on master ?? real-git-dir/Which strikes one as a bit inconsistent (since other pars of git-status knows to look in real-git-dir to find the index).
Sorry - no time to investigate.
You could even have a real git dir of some completely unrelated repository in your working tree, it will get reported as untracked, and you would probably not want to track its contents, either (or you might want to if you are trying to be funny, I dunno).
Quoted 4 lines
So I do not see there is anything to investigate. What you observed looks perfectly expected to me, except for the "mv .git real-git-dir" bit that makes a situation that confuses yourself (but not git).
.
The fact that the repo is stored in .git is an implementation detail - and one which git-status knows about (in the normal case).
In the gidir: case one part of git status understands the details (after all - it reads real-git-dir/index) while another part doesn't (after all - it show the actual repo as a normal directory).
Sure, git-real-dir could be added to git-real-dir/info/exclude. But by that logic we could insist on adding .git to .git/info/exclude.
The argument about an unrelated repo in the working tree is irrelevant - .git wouldn't point to it, so there's nothings special about it.
But it's obviously not a big deal either way and I'm gonna drop it.