-
Notifications
You must be signed in to change notification settings - Fork 811
Description
When using git in a shell to add a file to the working tree, the same file can be added in different ways. One way it can be added is by adding the bare filename:
$ git add my-file
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: my-file
Another way it can be added is by prefixing the filename with dot slash:
$ git add ./my-file
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: my-file
These both produce the same staged file to be added to the working tree.
However, when adding a file to the working tree using go-git
, the same file is stored with a different value in the git index. For example, adding the bare filename:
gitRepo, _ := git.PlainOpen("my-repo")
gitWorktree, _ := gitRepo.Worktree()
gitWorktree.Add("my-file")
Produces the expected staged file in the working tree:
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: my-file
But if the file is added with the prefixed dot slash:
gitRepo, _ := git.PlainOpen("my-repo")
gitWorktree, _ := gitRepo.Worktree()
gitWorktree.Add("./my-file")
A different file is staged:
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: ./my-file
I thought that it might have something to do with the shell expanding the dot slash but that doesn't seem to be the case since I tried adding the dot slash prefixed file using single quotes (git add './my-file'
) and got the same result.
To me, this is unexpected behavior with git. Is that indeed the case or am I missing something?