-
Notifications
You must be signed in to change notification settings - Fork 788
Worktree.Status() iterates through directories that are ignored in another .gitignore #736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It looks like this has already been fixed by @Achilleshiel in #1114 -- presumably should be picked up in 5.13. |
While #1114 seems to partially fix this problem, it still does not consider global gitignore files (e.g. EDIT: I noticed the |
From what I can tell, the fix in #1114 does not work if a directory that is not in the repo root (i.e. its in a another directory) has been ignored and contains a Assuming we have a repo with the following structure:
Where the top level foo and the other two !bar If we then check the status of the repo, func main() {
repo, _ := git.PlainOpen(".")
wt, _ := repo.Worktree()
status, _ := wt.Status()
fmt.Println(status) // Outputs: ?? subdir/foo/bar
fmt.Println(status.IsClean()) // Outputs: false
} |
The
Worktree.Status()
implementation does not ignore directories that are previously excluded by another.gitignore
, for example it will iterate through allnode_modules
in a repository, even when thesenode_modules
are ignored in the root.gitignore
.This leads to a funny behauvior, when you define another
.gitignore
, in an ignored sub directory, you can include files again with the!
operator in the second git ignore, which is respected by go git, but not bygit status
CLI.An example:
My root
.gitignore
contains the directorysub
# .gitignore sub
While in the directory
sub
, we have another.gitignore
, which has this content:And we have a
file.txt
in thesub
directory aswell:# sub/file.txt hello world
The implementation of go git will now show, that we have an unstaged file in
sub/file.txt
, while git itself does not have this behaviour when we usegit status
.I created a repository to reproduce this issue with an example: https://github.com/svenliebig/gogit-status-problem-example
git clone https://github.com/svenliebig/gogit-status-problem-example.git cd gogit-status-problem-example git status go run main.go
You'll see that both implementation return that no changes are made.
Let's run scripts.sh, this will create a file.txt in the directory sub, and add the directory to the
.gitignore
in the root.git status now shows that we have a change in
.gitignore
, while the implementation of go-git also shows the file.txt in their status implementation.This behaviour is produced in this dir.go file, where we iterate over all directories regardless if they where previously ignored or not.
The text was updated successfully, but these errors were encountered: