fix: correct pull for multiple repos

This commit is contained in:
2025-06-20 09:08:34 +03:00
parent 4c1f2ea90f
commit 51fdea781b
4 changed files with 46 additions and 39 deletions

View File

@ -68,33 +68,40 @@ func (rs *Repos) Pull(ctx context.Context, repos []types.Repo) error {
}
for _, repo := range repos {
urls := []string{repo.URL}
urls = append(urls, repo.Mirrors...)
var lastErr error
for i, repoURL := range urls {
if i > 0 {
slog.Info(gotext.Get("Trying mirror"), "repo", repo.Name, "mirror", repoURL)
}
err := rs.pullRepoFromURL(ctx, repoURL, repo)
if err != nil {
lastErr = err
slog.Warn(gotext.Get("Failed to pull from URL"), "repo", repo.Name, "url", repoURL, "error", err)
continue
}
// Success
return nil
err := rs.pullRepo(ctx, repo)
if err != nil {
return err
}
return fmt.Errorf("failed to pull repository %s from any URL: %w", repo.Name, lastErr)
}
return nil
}
func (rs *Repos) pullRepo(ctx context.Context, repo types.Repo) error {
urls := []string{repo.URL}
urls = append(urls, repo.Mirrors...)
var lastErr error
for i, repoURL := range urls {
if i > 0 {
slog.Info(gotext.Get("Trying mirror"), "repo", repo.Name, "mirror", repoURL)
}
err := rs.pullRepoFromURL(ctx, repoURL, repo)
if err != nil {
lastErr = err
slog.Warn(gotext.Get("Failed to pull from URL"), "repo", repo.Name, "url", repoURL, "error", err)
continue
}
// Success
return nil
}
return fmt.Errorf("failed to pull repository %s from any URL: %w", repo.Name, lastErr)
}
func readGitRepo(repoDir, repoUrl string) (*git.Repository, bool, error) {
gitDir := filepath.Join(repoDir, ".git")
if fi, err := os.Stat(gitDir); err == nil && fi.IsDir() {