-
Notifications
You must be signed in to change notification settings - Fork 13
fix: improve shallow clone guidance for synthetic history #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| package sources | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "log/slog" | ||
| "path/filepath" | ||
|
|
@@ -42,6 +43,20 @@ func MessageAffectsComponent(message, componentName string) bool { | |
| // whose message contains an "Affects: <componentName>" trailer line. Results are sorted | ||
| // chronologically (oldest first). | ||
| func FindAffectsCommits(repo *gogit.Repository, componentName string) ([]CommitMetadata, error) { | ||
| // Synthetic history depends on a complete project commit log so Affects | ||
| // trailers can be discovered reliably. | ||
| shallowCommits, err := repo.Storer.Shallow() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to inspect repository history depth:\n%w", err) | ||
| } | ||
|
|
||
| if len(shallowCommits) > 0 { | ||
| return nil, errors.New( | ||
| "repository is a shallow clone; synthetic history requires a full clone. " + | ||
| "Run `git fetch --unshallow` or re-clone without `--depth`", | ||
| ) | ||
| } | ||
|
Comment on lines
+53
to
+58
|
||
|
|
||
| head, err := repo.Head() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get HEAD reference:\n%w", err) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -10,6 +10,7 @@ import ( | |||
|
|
||||
| memfs "github.com/go-git/go-billy/v5/memfs" | ||||
| gogit "github.com/go-git/go-git/v5" | ||||
| "github.com/go-git/go-git/v5/plumbing" | ||||
| "github.com/go-git/go-git/v5/plumbing/object" | ||||
| "github.com/go-git/go-git/v5/storage/memory" | ||||
| "github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/core/sources" | ||||
|
|
@@ -112,6 +113,25 @@ func TestFindAffectsCommits_NoMatches(t *testing.T) { | |||
| assert.Empty(t, results) | ||||
| } | ||||
|
|
||||
| func TestFindAffectsCommits_ShallowRepo(t *testing.T) { | ||||
| repo := createInMemoryRepo(t) | ||||
|
|
||||
| addCommit(t, repo, | ||||
| "Fix CVE-2025-1234\n\nAffects: curl", | ||||
| "Alice", "alice@example.com", | ||||
| time.Date(2025, 1, 1, 10, 0, 0, 0, time.UTC)) | ||||
|
|
||||
| head, err := repo.Head() | ||||
| require.NoError(t, err) | ||||
| require.NoError(t, repo.Storer.SetShallow([]plumbing.Hash{head.Hash()})) | ||||
|
|
||||
| results, err := sources.FindAffectsCommits(repo, "curl") | ||||
| require.Error(t, err) | ||||
| assert.Nil(t, results) | ||||
| assert.Contains(t, err.Error(), "shallow clone") | ||||
|
||||
| assert.Contains(t, err.Error(), "shallow clone") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
repo.Storer.Shallow()can return an "unsupported" error depending on the underlying go-git storage implementation; failing hard here would incorrectly break synthetic history for storers that don't support shallow metadata (even when the repo is effectively "full"). Consider special-casing the go-git "shallow unsupported" error to treat it as non-shallow, and only error for unexpected failures.