Skip to content

Commit e1f2867

Browse files
author
Adam C. Foltzer
committedMar 17, 2017
use rev-parse to find repo root
Fix adapted from @snoyberg in acfoltzer#11
1 parent a0cd8fe commit e1f2867

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed
 

‎src/Development/GitRev.hs

+14-4
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ runGit args def useIdx = do
8989
ExitFailure _ -> return def
9090
else return def
9191

92-
-- | Determine where our git directory is, in case we're in a
92+
-- | Determine where our @.git@ directory is, in case we're in a
9393
-- submodule.
94-
getGitDirectory :: IO FilePath
95-
getGitDirectory = do
96-
pwd <- getCurrentDirectory
94+
getDotGit :: IO FilePath
95+
getDotGit = do
96+
pwd <- getGitRoot
9797
let dotGit = pwd </> ".git"
9898
oops = return dotGit -- it's gonna fail, that's fine
9999
isDir <- doesDirectoryExist dotGit
@@ -109,6 +109,16 @@ getGitDirectory = do
109109
else oops
110110
_ -> oops
111111

112+
-- | Get the root directory of the Git repo.
113+
getGitRoot :: IO FilePath
114+
getGitRoot = do
115+
pwd <- getCurrentDirectory
116+
(code, out, err) <-
117+
readProcessWithExitCode "git" ["rev-parse", "--show-toplevel"] ""
118+
case code of
119+
ExitSuccess -> return $ takeWhile (/= '\n') out
120+
ExitFailure _ -> return pwd -- later steps will fail, that's fine
121+
112122
-- | Type to flag if the git index is used or not in a call to runGit
113123
data IndexUsed = IdxUsed -- ^ The git index is used
114124
| IdxNotUsed -- ^ The git index is /not/ used

0 commit comments

Comments
 (0)
Please sign in to comment.