diff --git a/CHANGELOG.md b/CHANGELOG.md index dd8d30f4..3fb5b1d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) ### Added - integration tests on windows, ubuntu, and mac for github - GHORG_MATCH_REGEX to filter cloning repos by regex; thanks @petomalina +- fetch all if checkout fails when repo exists locally then retry ### Changed - initial clone will try to checkout a branch if specified; thanks @dword-design - default clone directory to $HOME/ghorg diff --git a/cmd/clone.go b/cmd/clone.go index 3f00aab3..24a7f764 100644 --- a/cmd/clone.go +++ b/cmd/clone.go @@ -363,10 +363,21 @@ func CloneAllRepos() { cmd := exec.Command("git", "checkout", branch) cmd.Dir = repoDir err := cmd.Run() + if err != nil { - e := fmt.Sprintf("Could not checkout out %s, branch may not exist, no changes made Repo: %s Error: %v", branch, repo.URL, err) - cloneInfos = append(cloneInfos, e) - return + cmd = exec.Command("git", "fetch", "--all") + cmd.Dir = repoDir + err = cmd.Run() + + cmd = exec.Command("git", "checkout", branch) + cmd.Dir = repoDir + err = cmd.Run() + + if err != nil { + e := fmt.Sprintf("Could not checkout out %s, branch may not exist, no changes made Repo: %s Error: %v", branch, repo.URL, err) + cloneInfos = append(cloneInfos, e) + return + } } cmd = exec.Command("git", "clean", "-f", "-d")