v0.7.8 - Bouton Arreter pour annuler les telechargements
Changements : - Bouton Arreter dans la barre de boutons (actif pendant les operations) - Annulation des operations git en cours via context.Context - Detection et affichage du message Annule dans le journal Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
17
git.go
17
git.go
@@ -280,8 +280,8 @@ func parseGitProgress(line string) (ProgressInfo, bool) {
|
||||
|
||||
// runGitWithProgress exécute une commande git et capture la progression en temps réel.
|
||||
// Le timeout est désactivé (0) ou très long pour les gros dépôts.
|
||||
func runGitWithProgress(args []string, cwd string, timeout time.Duration, cb ProgressCallback) (int, string, string) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
func runGitWithProgress(parent context.Context, args []string, cwd string, timeout time.Duration, cb ProgressCallback) (int, string, string) {
|
||||
ctx, cancel := context.WithTimeout(parent, timeout)
|
||||
defer cancel()
|
||||
|
||||
fullArgs := append([]string{"-c", "safe.directory=*"}, args...)
|
||||
@@ -339,6 +339,9 @@ func runGitWithProgress(args []string, cwd string, timeout time.Duration, cb Pro
|
||||
stderr := strings.TrimSpace(stderrBuf.String())
|
||||
|
||||
if err != nil {
|
||||
if ctx.Err() == context.Canceled {
|
||||
return 1, stdout, "Annulé"
|
||||
}
|
||||
if ctx.Err() == context.DeadlineExceeded {
|
||||
return 1, stdout, "Timeout"
|
||||
}
|
||||
@@ -352,7 +355,7 @@ func runGitWithProgress(args []string, cwd string, timeout time.Duration, cb Pro
|
||||
}
|
||||
|
||||
// doCloneWithProgress clone un dépôt avec suivi de progression.
|
||||
func doCloneWithProgress(cfg RepoConfig, cb ProgressCallback) error {
|
||||
func doCloneWithProgress(ctx context.Context, cfg RepoConfig, cb ProgressCallback) error {
|
||||
local := absRepoPath(cfg.Path)
|
||||
if err := os.MkdirAll(filepath.Dir(local), 0755); err != nil {
|
||||
return err
|
||||
@@ -362,7 +365,7 @@ func doCloneWithProgress(cfg RepoConfig, cb ProgressCallback) error {
|
||||
entries, _ := os.ReadDir(local)
|
||||
if len(entries) == 0 {
|
||||
code, _, stderr := runGitWithProgress(
|
||||
[]string{"clone", "--progress", cfg.URL, local},
|
||||
ctx, []string{"clone", "--progress", cfg.URL, local},
|
||||
"", 2*time.Hour, cb,
|
||||
)
|
||||
if code != 0 {
|
||||
@@ -383,7 +386,7 @@ func doCloneWithProgress(cfg RepoConfig, cb ProgressCallback) error {
|
||||
}
|
||||
|
||||
code, _, stderr = runGitWithProgress(
|
||||
[]string{"fetch", "--progress", "origin"},
|
||||
ctx, []string{"fetch", "--progress", "origin"},
|
||||
local, 2*time.Hour, cb,
|
||||
)
|
||||
if code != 0 {
|
||||
@@ -405,13 +408,13 @@ func doCloneWithProgress(cfg RepoConfig, cb ProgressCallback) error {
|
||||
}
|
||||
|
||||
// doPullWithProgress fait un pull avec suivi de progression.
|
||||
func doPullWithProgress(res RepoResult, cb ProgressCallback) error {
|
||||
func doPullWithProgress(ctx context.Context, res RepoResult, cb ProgressCallback) error {
|
||||
_, branch, _ := runGit([]string{"rev-parse", "--abbrev-ref", "HEAD"}, res.Path, 5*time.Second)
|
||||
if branch == "" {
|
||||
branch = "master"
|
||||
}
|
||||
code, _, stderr := runGitWithProgress(
|
||||
[]string{"pull", "--progress", "origin", branch},
|
||||
ctx, []string{"pull", "--progress", "origin", branch},
|
||||
res.Path, 2*time.Hour, cb,
|
||||
)
|
||||
if code != 0 {
|
||||
|
||||
Reference in New Issue
Block a user