Skip to content

Commit 8a3e6e7

Browse files
authored
fix: handle go-git extension validation errors gracefully (#2970)
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
1 parent d88676d commit 8a3e6e7

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

pkg/attestation/crafter/crafter.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,13 @@ func gracefulGitRepoHead(path string) (*HeadCommit, error) {
321321
})
322322

323323
if err != nil {
324-
if errors.Is(err, git.ErrRepositoryNotExists) {
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.
327+
if errors.Is(err, git.ErrRepositoryNotExists) ||
328+
errors.Is(err, git.ErrUnsupportedExtensionRepositoryFormatVersion) ||
329+
errors.Is(err, git.ErrUnknownExtension) ||
330+
errors.Is(err, git.ErrUnsupportedRepositoryFormatVersion) {
325331
return nil, nil
326332
}
327333

pkg/attestation/crafter/crafter_unit_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,30 @@ func (s *crafterUnitSuite) TestGitRepoHead() {
152152
name: "not a repository",
153153
wantNoCommit: true,
154154
},
155+
{
156+
name: "repo with unsupported extension degrades gracefully",
157+
repoProvider: func(repoPath string) (*HeadCommit, error) {
158+
// Init a repo and add a worktreeConfig extension to trigger
159+
// go-git's strict extension validation (added in v5.17.0)
160+
if _, err := git.PlainInit(repoPath, false); err != nil {
161+
return nil, err
162+
}
163+
164+
// Write the extension directly into the git config file
165+
gitConfigPath := filepath.Join(repoPath, ".git", "config")
166+
f, err := os.OpenFile(gitConfigPath, os.O_APPEND|os.O_WRONLY, 0o600)
167+
if err != nil {
168+
return nil, err
169+
}
170+
defer f.Close()
171+
if _, err := f.WriteString("[extensions]\n\tworktreeConfig = true\n"); err != nil {
172+
return nil, err
173+
}
174+
175+
return nil, nil
176+
},
177+
wantNoCommit: true,
178+
},
155179
}
156180

157181
for _, tc := range testCases {

0 commit comments

Comments
 (0)