Subject: Re: GIT_DIR not auto ignored

From: Dennis Kaarsemaker <[email-masked]>
Date: Sun, 01 Dec 2013 19:30:11 +0100

On zo, 2013-12-01 at 19:08 +0100, Dennis Kaarsemaker wrote:
> On za, 2013-11-30 at 23:06 -0800, Ingy dot Net wrote:
> > Greetings,
> > 
> > I found this probable bug:
> > https://gist.github.com/anonymous/01979fd9e6e285df41a2
> 
> Summary:
> 
> $ mv .git .foo
> $ export GIT_DIR=$PWD/.foo
> $ git status
> # On branch master
> #
> # Initial commit
> #
> # Untracked files:
> # .foo/
> nothing added to commit but untracked files present
> 
> 
> I checked with 1.8.5 and this still happens. 

This makes it go away:

diff --git a/dir.c b/dir.c
index 23b6de4..884b37d 100644
--- a/dir.c
+++ b/dir.c
@@ -1198,7 +1198,7 @@ static enum path_treatment treat_path(struct dir_struct *dir,
                return path_none;
        strbuf_setlen(path, baselen);
        strbuf_addstr(path, de->d_name);
-       if (simplify_away(path->buf, path->len, simplify))
+       if (simplify_away(path->buf, path->len, simplify) || is_git_directory(path->buf))
                return path_none;
 
        dtype = DTYPE(de);

I'll add a test and submit a proper patch.

> And this also happens:
> 
> $ mv .git .foo 
> $ export GIT_DIR=.foo
> dennis@lightning:~/code/git$ touch .git
> dennis@lightning:~/code/git$ git status
> On branch master
> Untracked files:
>   (use "git add <file>..." to include in what will be committed)
> 
> 	.foo/
> 
> nothing added to commit but untracked files present (use "git add" to
> track)
> 
> (Note the absence of .git there)

Comments in dir.c indicate that this is expected, so I didn't try to
"fix" that.

-- 
Dennis Kaarsemaker
www.kaarsemaker.net