File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,11 @@ func check() error {
1717 return errors .New ("git command not found in your system's PATH. Please install Git and try again" )
1818 }
1919
20+ // Check if current working directory is inside a Git repository.
21+ if ! util .IsGitRepo () {
22+ return errors .New ("not a git repository" )
23+ }
24+
2025 // Apply configuration values from CLI flags to Viper
2126 if diffUnified != 3 {
2227 viper .Set ("git.diff_unified" , diffUnified )
Original file line number Diff line number Diff line change 11package util
22
33import (
4+ "bytes"
45 "os/exec"
56 "strings"
67)
@@ -35,3 +36,16 @@ func ConvertToMap(args []string) Data {
3536 }
3637 return m
3738}
39+
40+ // IsGitRepo returns true if the current working directory is inside a Git work tree.
41+ func IsGitRepo () bool {
42+ cmd := exec .Command ("git" , "rev-parse" , "--is-inside-work-tree" )
43+
44+ var out bytes.Buffer
45+ cmd .Stdout = & out
46+ if err := cmd .Run (); err != nil {
47+ return false
48+ }
49+
50+ return strings .TrimSpace (out .String ()) == "true"
51+ }
You can’t perform that action at this time.
0 commit comments