Skip to content

Commit

Permalink
fix: Empty project failed status (#43)
Browse files Browse the repository at this point in the history
After updating go-git v5.4.3 -> v5.11.0, an empty commit returns an error.
It is due to change go-git/go-git#623
Added property to commit to allowing empty commit.

Change-Id: I8bd83e42e282dff78976276039159f1f1e647ad5
  • Loading branch information
zmotso committed Mar 1, 2024
1 parent f31c294 commit a616a03
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/git/git.go
Expand Up @@ -205,6 +205,7 @@ func (*GitProvider) CommitChanges(directory, commitMsg string, ops ...CommitOps)
Email: "codebase@edp.local",
When: time.Now(),
},
AllowEmptyCommits: option.allowEmptyCommit,
})
if err != nil {
return fmt.Errorf("failed to commit: %w", err)
Expand Down
33 changes: 32 additions & 1 deletion pkg/git/git_test.go
Expand Up @@ -210,6 +210,7 @@ func TestGitProvider_CommitChanges(t *testing.T) {

tests := []struct {
name string
ops []git.CommitOps
initRepo func(t *testing.T) string
wantErr require.ErrorAssertionFunc
checkRepo func(t *testing.T, dir string)
Expand Down Expand Up @@ -271,6 +272,36 @@ func TestGitProvider_CommitChanges(t *testing.T) {
require.Equalf(t, 0, count, "expected 0 commits, got %d", count)
},
},
{
name: "should create empty commit",
ops: []git.CommitOps{
git.CommitAllowEmpty(),
},
initRepo: func(t *testing.T) string {
dir := t.TempDir()
_, err := gogit.PlainInit(dir, false)
require.NoError(t, err)

return dir
},
wantErr: require.NoError,
checkRepo: func(t *testing.T, dir string) {
r, err := gogit.PlainOpen(dir)
require.NoError(t, err)

commits, err := r.CommitObjects()
require.NoError(t, err)

count := 0
_ = commits.ForEach(func(*object.Commit) error {
count++

return nil
})

require.Equalf(t, 1, count, "expected 1 commits, got %d", count)
},
},
}

for _, tt := range tests {
Expand All @@ -281,7 +312,7 @@ func TestGitProvider_CommitChanges(t *testing.T) {
gp := &git.GitProvider{}
dir := tt.initRepo(t)

err := gp.CommitChanges(dir, "test commit message")
err := gp.CommitChanges(dir, "test commit message", tt.ops...)
tt.wantErr(t, err)
tt.checkRepo(t, dir)
})
Expand Down

0 comments on commit a616a03

Please sign in to comment.