Skip to content

Commit 7fa0aa2

Browse files
committed
fix(test): configure git user in TestCommitChangelog for CI
The test relied on global git config for author identity, which is not available in CI environments.
1 parent 60aa9be commit 7fa0aa2

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/.idea/
33
/dist/
44
since
5+
.claude/*.local.json

vcs/operations_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,25 @@ func TestCheckBranch_wrongBranch(t *testing.T) {
5252
func TestCommitChangelog(t *testing.T) {
5353
repoDir := createTestRepo(t)
5454

55-
changelogPath := path.Join(repoDir, "CHANGELOG.md")
56-
err := os.WriteFile(changelogPath, []byte("# Changelog\n"), 0644)
55+
// configure git user so CommitChangelog can create a commit without
56+
// relying on the global git config (which may not exist in CI)
57+
repo, err := git.PlainOpen(repoDir)
5758
if err != nil {
5859
t.Fatal(err)
5960
}
60-
61-
// stage the file first via worktree
62-
repo, err := git.PlainOpen(repoDir)
61+
cfg, err := repo.Config()
6362
if err != nil {
6463
t.Fatal(err)
6564
}
66-
w, err := repo.Worktree()
65+
cfg.User.Name = "user"
66+
cfg.User.Email = "user@example.com"
67+
err = repo.SetConfig(cfg)
6768
if err != nil {
6869
t.Fatal(err)
6970
}
70-
_, err = w.Add("CHANGELOG.md")
71+
72+
changelogPath := path.Join(repoDir, "CHANGELOG.md")
73+
err = os.WriteFile(changelogPath, []byte("# Changelog\n"), 0644)
7174
if err != nil {
7275
t.Fatal(err)
7376
}

0 commit comments

Comments
 (0)