1
1
mirror of https://github.com/cooperspencer/gickup synced 2024-10-18 07:38:08 +02:00

It also updated when the source repo was force pushed

This commit is contained in:
Andreas Wachter 2024-04-26 08:04:47 +02:00
parent 0e76cf9481
commit 67dd7dceab

@ -142,13 +142,15 @@ func Locally(repo types.Repo, l types.Local, dry bool) bool {
break break
} }
err = os.RemoveAll(filepath.Join(l.Path, repo.Name)) /*
if err != nil { err = os.RemoveAll(filepath.Join(l.Path, repo.Name))
dir, _ := filepath.Abs(filepath.Join(l.Path, repo.Name)) if err != nil {
sub.Warn(). dir, _ := filepath.Abs(filepath.Join(l.Path, repo.Name))
Str("repo", repo.Name).Err(err). sub.Warn().
Msgf("couldn't remove %s", types.Red(dir)) Str("repo", repo.Name).Err(err).
} Msgf("couldn't remove %s", types.Red(dir))
}
*/
sub.Warn().Err(err). sub.Warn().Err(err).
Msgf("retry %s from %s", types.Red(x), types.Red(tries)) Msgf("retry %s from %s", types.Red(x), types.Red(tries))
@ -176,26 +178,30 @@ func Locally(repo types.Repo, l types.Local, dry bool) bool {
sub.Warn(). sub.Warn().
Str("repo", repo.Name). Str("repo", repo.Name).
Msg(err.Error()) Msg(err.Error())
err = os.RemoveAll(filepath.Join(l.Path, repo.Name)) /*
if err != nil { err = os.RemoveAll(filepath.Join(l.Path, repo.Name))
dir, _ := filepath.Abs(filepath.Join(l.Path, repo.Name)) if err != nil {
sub.Warn(). dir, _ := filepath.Abs(filepath.Join(l.Path, repo.Name))
Str("repo", repo.Name).Err(err). sub.Warn().
Msgf("couldn't remove %s", types.Red(dir)) Str("repo", repo.Name).Err(err).
} Msgf("couldn't remove %s", types.Red(dir))
}
*/
break break
} else { } else {
sub.Warn(). sub.Warn().
Str("repo", repo.Name).Err(err). Str("repo", repo.Name).Err(err).
Msgf("retry %s from %s", types.Red(x), types.Red(tries)) Msgf("retry %s from %s", types.Red(x), types.Red(tries))
err = os.RemoveAll(filepath.Join(l.Path, repo.Name)) /*
if err != nil { err = os.RemoveAll(filepath.Join(l.Path, repo.Name))
dir, _ := filepath.Abs(filepath.Join(l.Path, repo.Name)) if err != nil {
sub.Warn(). dir, _ := filepath.Abs(filepath.Join(l.Path, repo.Name))
Str("repo", repo.Name).Err(err). sub.Warn().
Msgf("couldn't remove %s", types.Red(dir)) Str("repo", repo.Name).Err(err).
} Msgf("couldn't remove %s", types.Red(dir))
}
*/
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
@ -330,15 +336,24 @@ func updateRepository(reponame string, auth transport.AuthMethod, dry bool, l ty
return err return err
} }
} else { } else {
err = r.Fetch(&git.FetchOptions{Auth: auth, RemoteName: "origin", RefSpecs: []config.RefSpec{"+refs/*:refs/*"}}) // fetch to see if there are any unpullable commits, for example a force push
if !l.Bare { err = r.Fetch(&git.FetchOptions{Auth: auth, RemoteName: "origin"})
w, err := r.Worktree() if err != nil {
if err == git.NoErrAlreadyUpToDate { if err == git.NoErrAlreadyUpToDate {
err = nil err = nil
} else { } else {
return err return err
} }
}
if !l.Bare {
w, err := r.Worktree()
if err != nil {
if err == git.NoErrAlreadyUpToDate {
err = nil
} else {
return err
}
}
sub.Info(). sub.Info().
Msgf("pulling %s", types.Green(reponame)) Msgf("pulling %s", types.Green(reponame))
@ -348,6 +363,11 @@ func updateRepository(reponame string, auth transport.AuthMethod, dry bool, l ty
} else { } else {
return err return err
} }
// if everything was ok, fetch everything
err = r.Fetch(&git.FetchOptions{Auth: auth, RemoteName: "origin", RefSpecs: []config.RefSpec{"+refs/*:refs/*"}})
if err != nil {
return err
}
} }
} }
} }