update clone to fetch if checkout is unsuccessful (#145)

* update clone to fetch if checkout is unsuccessful when repo exists locally
This commit is contained in:
Jay Gabriels 2021-08-21 19:01:29 -07:00 committed by GitHub
parent 805b9266e7
commit 43f7c06eeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -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

View File

@ -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")