go-git / go-git

A highly extensible Git implementation in pure Go.
https://pkg.go.dev/github.com/go-git/go-git/v5
Apache License 2.0
5.95k stars 740 forks source link

bug: Worktree.AddGlob adds .git/HEAD #571

Closed jiping-s closed 1 month ago

jiping-s commented 2 years ago

version: v5.4.2

Worktree.AddGlob("*") includes .git files that shouldn't be there, e.g.

repo, err := git.PlainInit("newRepo", false)
wt, _ := repo.Worktree()
// create some files
wt.AddGlob("*"))
_, err = wt.Commit("initial commit", &git.CommitOptions{Author: &author})
// now .git/HEAD is part of the repo!
git show b880d9e428bfc2948fbd2b0cf2b0f4e43576834f
commit b880d9e428bfc2948fbd2b0cf2b0f4e43576834f
Author: foo <foo@dotcom>
Date:   Tue Aug 23 16:57:22 2022 +0300

    initial commit

diff --git a/.git/HEAD b/.git/HEAD
new file mode 100644
index 0000000..cb089cd
--- /dev/null
+++ b/.git/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/.git/objects/cb/089cd89a7d7686d284d8761201649346b5aa1c b/.git/objects/cb/089cd89a7d7686d284d8761201649346b5aa1c
new file mode 100644
index 0000000..ed4e0ce
Binary files /dev/null and b/.git/objects/cb/089cd89a7d7686d284d8761201649346b5aa1c differ
...
...
github-actions[bot] commented 2 months ago

To help us keep things tidy and focus on the active tasks, we've introduced a stale bot to spot issues/PRs that haven't had any activity in a while.

This particular issue hasn't had any updates or activity in the past 90 days, so it's been labeled as 'stale'. If it remains inactive for the next 30 days, it'll be automatically closed.

We understand everyone's busy, but if this issue is still important to you, please feel free to add a comment or make an update to keep it active.

Thanks for your understanding and cooperation!