summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDima Kotik <dkotik@gmail.com>2020-05-28 07:20:13 +0300
committerJesse Duffield <jessedduffield@gmail.com>2020-05-30 00:31:58 +1000
commite73f4c6b7e921194545213b088a87c36b0d559eb (patch)
tree22374c8299b5a0064f64174391c29096b0c0a3f5 /pkg
parentcf5cefb2d6bcfd0d403faca5875124eb9b0d7480 (diff)
Better CWD check for a git repository.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/app/app.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/pkg/app/app.go b/pkg/app/app.go
index fb5fb1e41..ef821aad6 100644
--- a/pkg/app/app.go
+++ b/pkg/app/app.go
@@ -131,9 +131,16 @@ func NewApp(config config.AppConfigurer, filterPath string) (*App, error) {
func (app *App) setupRepo() error {
// if we are not in a git repo, we ask if we want to `git init`
if err := app.OSCommand.RunCommand("git status"); err != nil {
- if !strings.Contains(err.Error(), "Not a git repository") {
+ cwd, err := os.Getwd()
+ if err != nil {
return err
}
+ info, _ := os.Stat(filepath.Join(cwd, ".git"))
+ if info != nil && info.IsDir() {
+ return err // Current directory appears to be a git repository.
+ }
+
+ // Offer to initialize a new repository in current directory.
fmt.Print(app.Tr.SLocalize("CreateRepo"))
response, _ := bufio.NewReader(os.Stdin).ReadString('\n')
if strings.Trim(response, " \n") != "y" {