diff --git a/cmd_get.go b/cmd_get.go index 900db3b..a12ea3b 100644 --- a/cmd_get.go +++ b/cmd_get.go @@ -13,6 +13,7 @@ import ( "strings" "sync" + "github.com/Songmu/gitconfig" "github.com/mattn/go-isatty" "github.com/urfave/cli/v3" "github.com/x-motemen/ghq/cmdutil" @@ -27,6 +28,15 @@ func doGet(ctx context.Context, cmd *cli.Command) error { parallel = cmd.Bool("parallel") silent = cmd.Bool("silent") ) + if !andLook { + v, err := gitconfig.Bool("ghq.look") + if err != nil && !gitconfig.IsNotFound(err) { + return err + } + if err == nil { + andLook = v + } + } g := &getter{ update: cmd.Bool("update"), shallow: cmd.Bool("shallow"), diff --git a/cmd_get_test.go b/cmd_get_test.go index a64bfc7..1ce413a 100644 --- a/cmd_get_test.go +++ b/cmd_get_test.go @@ -497,6 +497,31 @@ func TestBareLook(t *testing.T) { }) } +func TestLookFromGitConfig(t *testing.T) { + withFakeGitBackend(t, func(t *testing.T, tmproot string, _ *_cloneArgs, _ *_updateArgs) { + os.MkdirAll(filepath.Join(tmproot, "github.com", "motemen", "ghq", ".git"), 0755) + defer func(orig func(cmd *exec.Cmd) error) { + cmdutil.CommandRunner = orig + }(cmdutil.CommandRunner) + var lastCmd *exec.Cmd + cmdutil.CommandRunner = func(cmd *exec.Cmd) error { + lastCmd = cmd + return nil + } + + t.Cleanup(gitconfig.WithConfig(t, `[ghq] + look = true +`)) + err := newApp().Run([]string{"", "get", "https://github.com/motemen/ghq"}) + if err != nil { + t.Errorf("error should be nil, but: %s", err) + } + if lastCmd == nil { + t.Fatal("shell should have been launched") + } + }) +} + func TestDoGet_bulk(t *testing.T) { in := []string{ "github.com/x-motemen/ghq",