fix: correct pull for multiple repos
This commit is contained in:
		| @@ -11,7 +11,7 @@ | |||||||
|     <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> |     <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> | ||||||
|         <text x="33.5" y="15" fill="#010101" fill-opacity=".3">coverage</text> |         <text x="33.5" y="15" fill="#010101" fill-opacity=".3">coverage</text> | ||||||
|         <text x="33.5" y="14">coverage</text> |         <text x="33.5" y="14">coverage</text> | ||||||
|         <text x="86" y="15" fill="#010101" fill-opacity=".3">18.8%</text> |         <text x="86" y="15" fill="#010101" fill-opacity=".3">18.9%</text> | ||||||
|         <text x="86" y="14">18.8%</text> |         <text x="86" y="14">18.9%</text> | ||||||
|     </g> |     </g> | ||||||
| </svg> | </svg> | ||||||
|   | |||||||
| Before Width: | Height: | Size: 926 B After Width: | Height: | Size: 926 B | 
| @@ -68,33 +68,40 @@ func (rs *Repos) Pull(ctx context.Context, repos []types.Repo) error { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for _, repo := range repos { | 	for _, repo := range repos { | ||||||
| 		urls := []string{repo.URL} | 		err := rs.pullRepo(ctx, repo) | ||||||
| 		urls = append(urls, repo.Mirrors...) | 		if err != nil { | ||||||
|  | 			return err | ||||||
| 		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) |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return nil | 	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) { | func readGitRepo(repoDir, repoUrl string) (*git.Repository, bool, error) { | ||||||
| 	gitDir := filepath.Join(repoDir, ".git") | 	gitDir := filepath.Join(repoDir, ".git") | ||||||
| 	if fi, err := os.Stat(gitDir); err == nil && fi.IsDir() { | 	if fi, err := os.Stat(gitDir); err == nil && fi.IsDir() { | ||||||
|   | |||||||
| @@ -383,27 +383,27 @@ msgstr "" | |||||||
| msgid "ERROR" | msgid "ERROR" | ||||||
| msgstr "" | msgstr "" | ||||||
|  |  | ||||||
| #: internal/repos/pull.go:78 | #: internal/repos/pull.go:88 | ||||||
| msgid "Trying mirror" | msgid "Trying mirror" | ||||||
| msgstr "" | msgstr "" | ||||||
|  |  | ||||||
| #: internal/repos/pull.go:84 | #: internal/repos/pull.go:94 | ||||||
| msgid "Failed to pull from URL" | msgid "Failed to pull from URL" | ||||||
| msgstr "" | msgstr "" | ||||||
|  |  | ||||||
| #: internal/repos/pull.go:151 | #: internal/repos/pull.go:158 | ||||||
| msgid "Pulling repository" | msgid "Pulling repository" | ||||||
| msgstr "" | msgstr "" | ||||||
|  |  | ||||||
| #: internal/repos/pull.go:188 | #: internal/repos/pull.go:195 | ||||||
| msgid "Repository up to date" | msgid "Repository up to date" | ||||||
| msgstr "" | msgstr "" | ||||||
|  |  | ||||||
| #: internal/repos/pull.go:223 | #: internal/repos/pull.go:230 | ||||||
| msgid "Git repository does not appear to be a valid ALR repo" | msgid "Git repository does not appear to be a valid ALR repo" | ||||||
| msgstr "" | msgstr "" | ||||||
|  |  | ||||||
| #: internal/repos/pull.go:239 | #: internal/repos/pull.go:246 | ||||||
| msgid "" | msgid "" | ||||||
| "ALR repo's minimum ALR version is greater than the current version. Try " | "ALR repo's minimum ALR version is greater than the current version. Try " | ||||||
| "updating ALR if something doesn't work." | "updating ALR if something doesn't work." | ||||||
|   | |||||||
| @@ -12,8 +12,8 @@ msgstr "" | |||||||
| "MIME-Version: 1.0\n" | "MIME-Version: 1.0\n" | ||||||
| "Content-Type: text/plain; charset=UTF-8\n" | "Content-Type: text/plain; charset=UTF-8\n" | ||||||
| "Content-Transfer-Encoding: 8bit\n" | "Content-Transfer-Encoding: 8bit\n" | ||||||
| "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && " | "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" | ||||||
| "n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" | "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" | ||||||
| "X-Generator: Gtranslator 48.0\n" | "X-Generator: Gtranslator 48.0\n" | ||||||
|  |  | ||||||
| #: build.go:42 | #: build.go:42 | ||||||
| @@ -356,8 +356,8 @@ msgid "" | |||||||
| "This command is deprecated and would be removed in the future, use \"%s\" " | "This command is deprecated and would be removed in the future, use \"%s\" " | ||||||
| "instead!" | "instead!" | ||||||
| msgstr "" | msgstr "" | ||||||
| "Эта команда устарела и будет удалена в будущем, используйте вместо нее " | "Эта команда устарела и будет удалена в будущем, используйте вместо нее \"%s" | ||||||
| "\"%s\"!" | "\"!" | ||||||
|  |  | ||||||
| #: internal/db/db.go:76 | #: internal/db/db.go:76 | ||||||
| msgid "Database version mismatch; resetting" | msgid "Database version mismatch; resetting" | ||||||
| @@ -397,27 +397,27 @@ msgstr "%s %s загружается — %s/с\n" | |||||||
| msgid "ERROR" | msgid "ERROR" | ||||||
| msgstr "ОШИБКА" | msgstr "ОШИБКА" | ||||||
|  |  | ||||||
| #: internal/repos/pull.go:78 | #: internal/repos/pull.go:88 | ||||||
| msgid "Trying mirror" | msgid "Trying mirror" | ||||||
| msgstr "Пробую зеркало" | msgstr "Пробую зеркало" | ||||||
|  |  | ||||||
| #: internal/repos/pull.go:84 | #: internal/repos/pull.go:94 | ||||||
| msgid "Failed to pull from URL" | msgid "Failed to pull from URL" | ||||||
| msgstr "Не удалось извлечь из URL" | msgstr "Не удалось извлечь из URL" | ||||||
|  |  | ||||||
| #: internal/repos/pull.go:151 | #: internal/repos/pull.go:158 | ||||||
| msgid "Pulling repository" | msgid "Pulling repository" | ||||||
| msgstr "Скачивание репозитория" | msgstr "Скачивание репозитория" | ||||||
|  |  | ||||||
| #: internal/repos/pull.go:188 | #: internal/repos/pull.go:195 | ||||||
| msgid "Repository up to date" | msgid "Repository up to date" | ||||||
| msgstr "Репозиторий уже обновлён" | msgstr "Репозиторий уже обновлён" | ||||||
|  |  | ||||||
| #: internal/repos/pull.go:223 | #: internal/repos/pull.go:230 | ||||||
| msgid "Git repository does not appear to be a valid ALR repo" | msgid "Git repository does not appear to be a valid ALR repo" | ||||||
| msgstr "Репозиторий Git не поддерживается репозиторием ALR" | msgstr "Репозиторий Git не поддерживается репозиторием ALR" | ||||||
|  |  | ||||||
| #: internal/repos/pull.go:239 | #: internal/repos/pull.go:246 | ||||||
| msgid "" | msgid "" | ||||||
| "ALR repo's minimum ALR version is greater than the current version. Try " | "ALR repo's minimum ALR version is greater than the current version. Try " | ||||||
| "updating ALR if something doesn't work." | "updating ALR if something doesn't work." | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user