adjustment

This commit is contained in:
Zhizhen He 2023-02-24 13:42:09 +08:00
parent 67a22bf1f7
commit ef0d942544
No known key found for this signature in database
GPG key ID: B5A215D74FCFD6A7
2 changed files with 13 additions and 17 deletions

View file

@ -7,24 +7,20 @@ import (
)
func doRoot(c *cli.Context) error {
var (
w = c.App.Writer
all = c.Bool("all")
)
if all {
roots, err := localRepositoryRoots(true)
if err != nil {
return err
}
for _, root := range roots {
fmt.Fprintln(w, root)
}
return nil
}
root, err := primaryLocalRepositoryRoot()
roots, err := localRepositoryRoots(true)
if err != nil {
return err
}
fmt.Fprintln(w, root)
if !c.Bool("all") {
roots = roots[:1] // only the first root is needed
}
for _, root := range roots {
_, err := fmt.Fprintln(c.App.Writer, root)
if err != nil {
return err
}
}
return nil
}

View file

@ -117,10 +117,10 @@ func LocalRepositoryFromURL(remoteURL *url.URL) (*LocalRepository, error) {
func getRoot(u string) (string, error) {
prim := os.Getenv(envGhqRoot)
var err error
if prim != "" {
return prim, nil
}
var err error
if !codecommitLikeURLPattern.MatchString(u) {
prim, err = gitconfig.Do("--path", "--get-urlmatch", "ghq.root", u)
if err != nil && !gitconfig.IsNotFound(err) {