@@ -141,10 +141,13 @@ var (
141141)
142142
143143// findGitRoot checks whether the current directory is part of a git repo; if so,
144- // returns its root, otherwise returns empty string.
145- func findGitRoot () string {
144+ // returns its root, otherwise returns "." which is a good default for all
145+ // situations in which we want to optionally find the root of a repo but we are
146+ // unable to.
147+ func findGitRootOrCwd () string {
146148 if ! cachedGitRootOnce {
147149 cachedGitRootOnce = true
150+ cachedGitRoot = "."
148151
149152 rootdir1 , err := getOutput ("git" , "rev-parse" , "--show-toplevel" )
150153 if err == nil {
@@ -161,8 +164,16 @@ func findGitRoot() string {
161164// mustFindGitRoot is like findGitRoot, but aborts with fatal if no git repository
162165// is found.
163166func mustFindGitRoot () string {
164- path := findGitRoot ()
165- if path == "" {
167+ path := findGitRootOrCwd ()
168+ if path == "." {
169+ if _ , err := exec .LookPath ("git" ); err != nil {
170+ critical ("error: this command requires Git\n " )
171+ if runtime .GOOS == "windows" || true {
172+ fatal ("Please download it from: https://git-scm.com/downloads\n " )
173+ } else {
174+ fatal ("Please install it with your favorite package manager" )
175+ }
176+ }
166177 fatal ("error: this command must be run from a git repository\n " )
167178 }
168179 return path
@@ -207,10 +218,7 @@ func findLibdragon() (string, bool) {
207218func findDockerImage () string {
208219 // Check if there's a cached image file in the repository root. This is
209220 // a local override requested by the user, so it wins over anything.
210- repoRoot := findGitRoot ()
211- if repoRoot == "" {
212- repoRoot = "."
213- }
221+ repoRoot := findGitRootOrCwd ()
214222 if imagebytes , err := os .ReadFile (filepath .Join (repoRoot , CACHED_IMAGE_FILE )); err == nil {
215223 return strings .TrimSpace (string (imagebytes ))
216224 }
0 commit comments