Skip to content

Commit 62f35ce

Browse files
committed
bundles: fetch changes before building incremental bundle
Add an invocation of 'git fetch' to 'bundles.CreateIncrementalBundle()' before running 'git bundle' to ensure that the latest updates to the repository are captured in the bundle. If this is not done, the repository will never see any updates, and will never create an incremental bundle. Signed-off-by: Victoria Dye <[email protected]>
1 parent 2bd126d commit 62f35ce

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

internal/bundles/bundles.go

+6
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,12 @@ func (b *bundleProvider) CreateIncrementalBundle(ctx context.Context, repo *core
360360
ctx, exitRegion := b.logger.Region(ctx, "bundles", "create_incremental_bundle")
361361
defer exitRegion()
362362

363+
// Fetch latest updates to repo
364+
err := b.gitHelper.UpdateBareRepo(ctx, repo.RepoDir)
365+
if err != nil {
366+
return nil, fmt.Errorf("failed to fetch updates to repo: %w", err)
367+
}
368+
363369
bundle := b.createDistinctBundle(repo, list)
364370

365371
lines, err := b.getAllPrereqsForIncrementalBundle(list)

internal/git/git.go

+10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type GitHelper interface {
1616
CreateBundleFromRefs(ctx context.Context, repoDir string, filename string, refs map[string]string) error
1717
CreateIncrementalBundle(ctx context.Context, repoDir string, filename string, prereqs []string) (bool, error)
1818
CloneBareRepo(ctx context.Context, url string, destination string) error
19+
UpdateBareRepo(ctx context.Context, repoDir string) error
1920
}
2021

2122
type gitHelper struct {
@@ -139,3 +140,12 @@ func (g *gitHelper) CloneBareRepo(ctx context.Context, url string, destination s
139140

140141
return nil
141142
}
143+
144+
func (g *gitHelper) UpdateBareRepo(ctx context.Context, repoDir string) error {
145+
gitErr := g.gitCommand(ctx, "-C", repoDir, "fetch", "origin")
146+
if gitErr != nil {
147+
return g.logger.Errorf(ctx, "failed to fetch latest refs: %w", gitErr)
148+
}
149+
150+
return nil
151+
}

0 commit comments

Comments
 (0)