Skip to content

worktree.Add does not add a modified file correctly while git add works as expected #1003

@lambou123

Description

@lambou123

Development environment details:

  • Ubuntu 23.10
  • git 2.40.1
  • go-git v5.11.0

cat ~/.gitconfig

[merge]
   ff = false

I have a modified file (echo "new line" >> readme.txt).

If I run this code, I got a modified file in worktree and index at the same time with the same content.
If I run git add file, this will be added correctly :

r,err := git.PlainOpen(dir)
w, err := r.Worktree()
w.Add(file)

git diff shows no changes:

$ 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)
        modified:   readme.md

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   readme.md

If I run git add file, the output is like that:

$ 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)
        modified:   readme.md

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions