Skip to content

Commit 64e9bef

Browse files
committed
fix: keep go-git v5.17.1 and handle extension errors gracefully
Switches from string-based error matching to using go-git's exported error variables now that we stay on v5.17.1. Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
1 parent 73b801d commit 64e9bef

3 files changed

Lines changed: 9 additions & 21 deletions

File tree

go.mod

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,7 @@ require (
353353
github.com/emicklei/go-restful/v3 v3.13.0 // indirect
354354
github.com/fsnotify/fsnotify v1.9.0 // indirect
355355
github.com/fsouza/fake-gcs-server v1.47.6
356-
// Pinned to v5.16.5: v5.17.x has a case-sensitivity bug in extension validation
357-
// that breaks PlainOpen on repos using git worktree.
358-
// https://github.com/chainloop-dev/chainloop/issues/2966
359-
github.com/go-git/go-git/v5 v5.16.5
356+
github.com/go-git/go-git/v5 v5.17.1
360357
github.com/go-kratos/aegis v0.2.0 // indirect
361358
github.com/go-logr/logr v1.4.3 // indirect
362359
github.com/go-logr/stdr v1.2.2 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ github.com/go-git/go-billy/v5 v5.8.0/go.mod h1:RpvI/rw4Vr5QA+Z60c6d6LXH0rYJo0uD5
449449
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4=
450450
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
451451
github.com/go-git/go-git/v5 v5.11.0/go.mod h1:6GFcX2P3NM7FPBfpePbpLd21XxsgdAt+lKqXmCUiUCY=
452-
github.com/go-git/go-git/v5 v5.16.5 h1:mdkuqblwr57kVfXri5TTH+nMFLNUxIj9Z7F5ykFbw5s=
453-
github.com/go-git/go-git/v5 v5.16.5/go.mod h1:QOMLpNf1qxuSY4StA/ArOdfFR2TrKEjJiye2kel2m+M=
452+
github.com/go-git/go-git/v5 v5.17.1 h1:WnljyxIzSj9BRRUlnmAU35ohDsjRK0EKmL0evDqi5Jk=
453+
github.com/go-git/go-git/v5 v5.17.1/go.mod h1:pW/VmeqkanRFqR6AljLcs7EA7FbZaN5MQqO7oZADXpo=
454454
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
455455
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
456456
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=

pkg/attestation/crafter/crafter.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -312,20 +312,6 @@ type CommitRemote struct {
312312
// This error is not exposed by go-git
313313
var errBranchInvalidMerge = errors.New("branch config: invalid merge")
314314

315-
// isGitExtensionError returns true if the error is related to unsupported git
316-
// repository format extensions (e.g. worktreeConfig). go-git v5.17.0 introduced
317-
// strict validation that rejects repos with extensions it doesn't support.
318-
// See https://github.com/go-git/go-git/pull/1861
319-
func isGitExtensionError(err error) bool {
320-
if err == nil {
321-
return false
322-
}
323-
msg := err.Error()
324-
return strings.Contains(msg, "does not support extension") ||
325-
strings.Contains(msg, "unknown extension") ||
326-
strings.Contains(msg, "repositoryformatversion not supported")
327-
}
328-
329315
// Returns the current directory git commit hash if possible
330316
// If we are not in a git repo it will return an empty string
331317
func gracefulGitRepoHead(path string) (*HeadCommit, error) {
@@ -335,8 +321,13 @@ func gracefulGitRepoHead(path string) (*HeadCommit, error) {
335321
})
336322

337323
if err != nil {
324+
// go-git v5.17.0 introduced strict extension validation (go-git/go-git#1861)
325+
// that rejects repos with extensions it doesn't fully support (e.g. worktreeConfig).
326+
// Degrade gracefully instead of failing the attestation.
338327
if errors.Is(err, git.ErrRepositoryNotExists) ||
339-
isGitExtensionError(err) {
328+
errors.Is(err, git.ErrUnsupportedExtensionRepositoryFormatVersion) ||
329+
errors.Is(err, git.ErrUnknownExtension) ||
330+
errors.Is(err, git.ErrUnsupportedRepositoryFormatVersion) {
340331
return nil, nil
341332
}
342333

0 commit comments

Comments
 (0)