From 51fdea781be27296f1f11b43525fe9442623e626 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Fri, 20 Jun 2025 09:08:34 +0300 Subject: [PATCH] fix: correct pull for multiple repos --- assets/coverage-badge.svg | 4 +-- internal/repos/pull.go | 49 +++++++++++++++----------- internal/translations/default.pot | 12 +++---- internal/translations/po/ru/default.po | 20 +++++------ 4 files changed, 46 insertions(+), 39 deletions(-) diff --git a/assets/coverage-badge.svg b/assets/coverage-badge.svg index e1e8356..259d4b3 100644 --- a/assets/coverage-badge.svg +++ b/assets/coverage-badge.svg @@ -11,7 +11,7 @@ coverage coverage - 18.8% - 18.8% + 18.9% + 18.9% diff --git a/internal/repos/pull.go b/internal/repos/pull.go index d9beccb..e0944d8 100644 --- a/internal/repos/pull.go +++ b/internal/repos/pull.go @@ -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() { diff --git a/internal/translations/default.pot b/internal/translations/default.pot index b1c0bb1..ca81861 100644 --- a/internal/translations/default.pot +++ b/internal/translations/default.pot @@ -383,27 +383,27 @@ msgstr "" msgid "ERROR" msgstr "" -#: internal/repos/pull.go:78 +#: internal/repos/pull.go:88 msgid "Trying mirror" msgstr "" -#: internal/repos/pull.go:84 +#: internal/repos/pull.go:94 msgid "Failed to pull from URL" msgstr "" -#: internal/repos/pull.go:151 +#: internal/repos/pull.go:158 msgid "Pulling repository" msgstr "" -#: internal/repos/pull.go:188 +#: internal/repos/pull.go:195 msgid "Repository up to date" msgstr "" -#: internal/repos/pull.go:223 +#: internal/repos/pull.go:230 msgid "Git repository does not appear to be a valid ALR repo" msgstr "" -#: internal/repos/pull.go:239 +#: internal/repos/pull.go:246 msgid "" "ALR repo's minimum ALR version is greater than the current version. Try " "updating ALR if something doesn't work." diff --git a/internal/translations/po/ru/default.po b/internal/translations/po/ru/default.po index b8db48a..b109c78 100644 --- a/internal/translations/po/ru/default.po +++ b/internal/translations/po/ru/default.po @@ -12,8 +12,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && " -"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" "X-Generator: Gtranslator 48.0\n" #: build.go:42 @@ -356,8 +356,8 @@ msgid "" "This command is deprecated and would be removed in the future, use \"%s\" " "instead!" msgstr "" -"Эта команда устарела и будет удалена в будущем, используйте вместо нее " -"\"%s\"!" +"Эта команда устарела и будет удалена в будущем, используйте вместо нее \"%s" +"\"!" #: internal/db/db.go:76 msgid "Database version mismatch; resetting" @@ -397,27 +397,27 @@ msgstr "%s %s загружается — %s/с\n" msgid "ERROR" msgstr "ОШИБКА" -#: internal/repos/pull.go:78 +#: internal/repos/pull.go:88 msgid "Trying mirror" msgstr "Пробую зеркало" -#: internal/repos/pull.go:84 +#: internal/repos/pull.go:94 msgid "Failed to pull from URL" msgstr "Не удалось извлечь из URL" -#: internal/repos/pull.go:151 +#: internal/repos/pull.go:158 msgid "Pulling repository" msgstr "Скачивание репозитория" -#: internal/repos/pull.go:188 +#: internal/repos/pull.go:195 msgid "Repository up to date" msgstr "Репозиторий уже обновлён" -#: internal/repos/pull.go:223 +#: internal/repos/pull.go:230 msgid "Git repository does not appear to be a valid ALR repo" msgstr "Репозиторий Git не поддерживается репозиторием ALR" -#: internal/repos/pull.go:239 +#: internal/repos/pull.go:246 msgid "" "ALR repo's minimum ALR version is greater than the current version. Try " "updating ALR if something doesn't work."