Skip to content

Commit

Permalink
It also updated when the source repo was force pushed (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperspencer authored Apr 27, 2024
1 parent 0e76cf9 commit b596987
Showing 1 changed file with 45 additions and 25 deletions.
70 changes: 45 additions & 25 deletions local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,15 @@ func Locally(repo types.Repo, l types.Local, dry bool) bool {
break
}

err = os.RemoveAll(filepath.Join(l.Path, repo.Name))
if err != nil {
dir, _ := filepath.Abs(filepath.Join(l.Path, repo.Name))
sub.Warn().
Str("repo", repo.Name).Err(err).
Msgf("couldn't remove %s", types.Red(dir))
}
/*
err = os.RemoveAll(filepath.Join(l.Path, repo.Name))
if err != nil {
dir, _ := filepath.Abs(filepath.Join(l.Path, repo.Name))
sub.Warn().
Str("repo", repo.Name).Err(err).
Msgf("couldn't remove %s", types.Red(dir))
}
*/

sub.Warn().Err(err).
Msgf("retry %s from %s", types.Red(x), types.Red(tries))
Expand Down Expand Up @@ -176,26 +178,30 @@ func Locally(repo types.Repo, l types.Local, dry bool) bool {
sub.Warn().
Str("repo", repo.Name).
Msg(err.Error())
err = os.RemoveAll(filepath.Join(l.Path, repo.Name))
if err != nil {
dir, _ := filepath.Abs(filepath.Join(l.Path, repo.Name))
sub.Warn().
Str("repo", repo.Name).Err(err).
Msgf("couldn't remove %s", types.Red(dir))
}
/*
err = os.RemoveAll(filepath.Join(l.Path, repo.Name))
if err != nil {
dir, _ := filepath.Abs(filepath.Join(l.Path, repo.Name))
sub.Warn().
Str("repo", repo.Name).Err(err).
Msgf("couldn't remove %s", types.Red(dir))
}
*/
break
} else {
sub.Warn().
Str("repo", repo.Name).Err(err).
Msgf("retry %s from %s", types.Red(x), types.Red(tries))

err = os.RemoveAll(filepath.Join(l.Path, repo.Name))
if err != nil {
dir, _ := filepath.Abs(filepath.Join(l.Path, repo.Name))
sub.Warn().
Str("repo", repo.Name).Err(err).
Msgf("couldn't remove %s", types.Red(dir))
}
/*
err = os.RemoveAll(filepath.Join(l.Path, repo.Name))
if err != nil {
dir, _ := filepath.Abs(filepath.Join(l.Path, repo.Name))
sub.Warn().
Str("repo", repo.Name).Err(err).
Msgf("couldn't remove %s", types.Red(dir))
}
*/

time.Sleep(5 * time.Second)

Expand Down Expand Up @@ -330,15 +336,24 @@ func updateRepository(reponame string, auth transport.AuthMethod, dry bool, l ty
return err
}
} else {
err = r.Fetch(&git.FetchOptions{Auth: auth, RemoteName: "origin", RefSpecs: []config.RefSpec{"+refs/*:refs/*"}})
if !l.Bare {
w, err := r.Worktree()
// fetch to see if there are any unpullable commits, for example a force push
err = r.Fetch(&git.FetchOptions{Auth: auth, RemoteName: "origin"})
if err != nil {
if err == git.NoErrAlreadyUpToDate {
err = nil
} else {
return err
}

}
if !l.Bare {
w, err := r.Worktree()
if err != nil {
if err == git.NoErrAlreadyUpToDate {
err = nil
} else {
return err
}
}
sub.Info().
Msgf("pulling %s", types.Green(reponame))

Expand All @@ -348,6 +363,11 @@ func updateRepository(reponame string, auth transport.AuthMethod, dry bool, l ty
} else {
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
}
}
}
}
Expand Down

0 comments on commit b596987

Please sign in to comment.