Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions internal/app/azldev/core/sources/synthistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package sources

import (
"errors"
"fmt"
"log/slog"
"path/filepath"
Expand Down Expand Up @@ -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)
}
Comment on lines +48 to +51
Copy link

Copilot AI Apr 21, 2026

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.

Copilot uses AI. Check for mistakes.

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
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a new, user-actionable failure mode that callers may want to detect programmatically (and tests currently can only validate via substring checks). Consider introducing a sentinel/typed error (e.g., ErrShallowClone) and wrapping it (so callers can errors.Is(err, ErrShallowClone)), while keeping the detailed guidance in the message.

Copilot uses AI. Check for mistakes.

head, err := repo.Head()
if err != nil {
return nil, fmt.Errorf("failed to get HEAD reference:\n%w", err)
Expand Down
20 changes: 20 additions & 0 deletions internal/app/azldev/core/sources/synthistory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assertions are tightly coupled to the exact error phrasing and may become brittle if the message is later tweaked. If you adopt a sentinel/typed error for shallow clones, prefer asserting with errors.Is (or require.ErrorIs) and keep only one message substring assertion for the user guidance.

Suggested change
assert.Contains(t, err.Error(), "shallow clone")

Copilot uses AI. Check for mistakes.
assert.Contains(t, err.Error(), "git fetch --unshallow")
}

func TestFindAffectsCommits_MultipleComponents(t *testing.T) {
repo := createInMemoryRepo(t)

Expand Down
Loading