Skip to content

Commit

Permalink
brush up doctor command messages
Browse files Browse the repository at this point in the history
  • Loading branch information
uetchy committed Aug 4, 2018
1 parent bea3e37 commit dffe701
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions command_doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,62 +33,56 @@ func doDoctor(c *cli.Context) error {
trimmedLocal := strings.TrimPrefix(repo.Path, ghqPath+"/")

if remoteOriginURL == "" {
fmt.Println("===>", trimmedLocal, "'remote.origin' doesn't exist")
fmt.Println("===> 'remote.origin.url' does not exist in", trimmedLocal)
if fixupIssues {
okToChange := prompter.YN("===> Fix remote.origin to"+trimmedLocal+"?", true)
okToChange := prompter.YN("===> Add "+trimmedLocal+" to 'remote.origin' ?", true)
if okToChange {
slp := strings.Split(trimmedLocal, "/")
remotePathFromLocal := fmt.Sprintf("git@%s:%s/%s.git", slp[0], slp[1], slp[2])
fmt.Println(remotePathFromLocal)
err := GitRemoteAdd(repo.Path, "origin", remotePathFromLocal)
if err != nil {
fmt.Println("===> Fix failed")
fmt.Println(err)
fmt.Println("===> Fix failed because of", err)
} else {
fmt.Println("===> Fixed")
fmt.Println(remotePathFromLocal)
fmt.Println("===> Add", remotePathFromLocal, "to", repo.Path)
}
} else {
fmt.Println()
}
}
} else if trimmedRemote != trimmedLocal && !strings.Contains(trimmedLocal, "golang.org/x/") {
fmt.Println("===>", trimmedLocal, "'remote.origin' has changed")
fmt.Println("Remote:", trimmedRemote)
fmt.Println("===> 'remote.origin.url' has been changed")
fmt.Println("===> local ", trimmedLocal)
fmt.Println("===> remote", trimmedRemote)
if fixupIssues {
fmt.Println("===> Fixup mode")
fmt.Println("===> Choose the right location for" + trimmedLocal)
fmt.Println("[1] " + trimmedLocal)
fmt.Println("[2] " + trimmedRemote)
choice := prompter.Choose("===> Choose the right location", []string{"1", "2"}, "1")
choice := prompter.Choose("===>", []string{"1", "2"}, "1")
if choice == "1" {
// Change remote.origin
slp := strings.Split(trimmedLocal, "/")
remotePathFromLocal := fmt.Sprintf("git@%s:%s/%s.git", slp[0], slp[1], slp[2])
err := GitRemoteSetURL(repo.Path, "origin", remotePathFromLocal)
if err != nil {
fmt.Println("===> Fix failed")
fmt.Println(err)
fmt.Println("===> Failed because of", err)
continue
}
fmt.Println("===> Fixed")
fmt.Println(remotePathFromLocal)
fmt.Println("===> Change remote.origin.url to", remotePathFromLocal)
} else {
// Move directory
localPathFromRemote := filepath.Join(ghqPath, trimmedRemote)
fmt.Println(localPathFromRemote)
if _, err := os.Stat(localPathFromRemote); os.IsExist(err) {
fmt.Println("===> Fix failed")
fmt.Println(localPathFromRemote, "already exist")
fmt.Println("===> Fix failed because", localPathFromRemote, "already exist")
continue
}

if err := os.Rename(repo.Path, localPathFromRemote); err != nil {
fmt.Println("===> Fix failed")
fmt.Println(err)
fmt.Println("===> Fix failed because of", err)
continue
}
fmt.Println("===> Fixed")
fmt.Println(localPathFromRemote)
fmt.Println("===> Move repository from", repo.Path, "to", localPathFromRemote)
}
}
}
Expand Down

0 comments on commit dffe701

Please sign in to comment.