Skip to content

Commit ab80861

Browse files
authored
fix(cli attestation): handle non-merged branches (#451)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent cd122f9 commit ab80861

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

internal/attestation/crafter/crafter.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ type CommitRemote struct {
253253
Name, URL string
254254
}
255255

256+
// This error is not exposed by go-git
257+
var errBranchInvalidMerge = errors.New("branch config: invalid merge")
258+
256259
// Returns the current directory git commit hash if possible
257260
// If we are not in a git repo it will return an empty string
258261
func gracefulGitRepoHead(path string) (*HeadCommit, error) {
@@ -293,6 +296,14 @@ func gracefulGitRepoHead(path string) (*HeadCommit, error) {
293296

294297
remotes, err := repo.Remotes()
295298
if err != nil {
299+
// go-git does an additional validation that the branch is pushed upstream
300+
// we do not care about that use-case, so we ignore the error
301+
// we compare by error string because go-git does not expose the error type
302+
// and errors.Is require the same instance of the error
303+
if err.Error() == errBranchInvalidMerge.Error() {
304+
return c, nil
305+
}
306+
296307
return nil, fmt.Errorf("getting remotes: %w", err)
297308
}
298309

0 commit comments

Comments
 (0)