fix(gitstore): adjust garbage collection to run after push operation
- Updated `maybeRunGC` to accept `repoDir` instead of `repo`. - Moved garbage collection trigger to occur after the push step for improved reliability. - Added a test to validate the sequence of push and GC operations. Closes: #3373
This commit is contained in:
@@ -858,7 +858,6 @@ func (s *GitTokenStore) commitAndPushLocked(message string, relPaths ...string)
|
||||
} else if errRewrite := s.rewriteHeadAsSingleCommit(repo, headRef.Name(), commitHash, message, signature); errRewrite != nil {
|
||||
return errRewrite
|
||||
}
|
||||
s.maybeRunGC(repo)
|
||||
pushOpts := &git.PushOptions{Auth: s.gitAuth(), Force: true}
|
||||
if s.branch != "" {
|
||||
pushOpts.RefSpecs = []config.RefSpec{config.RefSpec("refs/heads/" + s.branch + ":refs/heads/" + s.branch)}
|
||||
@@ -874,6 +873,7 @@ func (s *GitTokenStore) commitAndPushLocked(message string, relPaths ...string)
|
||||
}
|
||||
return fmt.Errorf("git token store: push: %w", err)
|
||||
}
|
||||
s.maybeRunGC(repoDir)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -907,13 +907,18 @@ func (s *GitTokenStore) rewriteHeadAsSingleCommit(repo *git.Repository, branch p
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *GitTokenStore) maybeRunGC(repo *git.Repository) {
|
||||
func (s *GitTokenStore) maybeRunGC(repoDir string) {
|
||||
now := time.Now()
|
||||
if now.Sub(s.lastGC) < gcInterval {
|
||||
return
|
||||
}
|
||||
s.lastGC = now
|
||||
|
||||
repo, err := git.PlainOpen(repoDir)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
pruneOpts := git.PruneOptions{
|
||||
OnlyObjectsOlderThan: now,
|
||||
Handler: repo.DeleteObject,
|
||||
|
||||
Reference in New Issue
Block a user