From fbb0b51728f6179ffe144a787608c8e7f00b9b86 Mon Sep 17 00:00:00 2001 From: supersonic-copycat <134552638+supersonic-copycat@users.noreply.github.com> Date: Fri, 15 Aug 2025 12:17:31 +0300 Subject: [PATCH] check also for path existence doesDirExists returns False if either path does not exist or it's not a directory. If file dos not exists code execution goes to `getGitFilesForWorktree` and leads to misleading error message like \cygdrive\c\...\.git: openBinaryFile: does not exist (No such file or directory) while `.git` exists and is indeed a directory! --- src/GitHash.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/GitHash.hs b/src/GitHash.hs index affd64e..3f7c0e0 100644 --- a/src/GitHash.hs +++ b/src/GitHash.hs @@ -73,6 +73,7 @@ import System.Exit import System.FilePath import System.IO.Error (isDoesNotExistError) import System.Process +import System.IO (hPutStrLn, stderr) import Text.Read (readMaybe) -- | Various pieces of information about a Git repository. @@ -221,8 +222,14 @@ getGitFilesForWorktree git = do -- | Get a list of dependent git related files. getGitFiles :: FilePath -> IO [FilePath] getGitFiles git = do + exists <- doesPathExist git isDir <- doesDirectoryExist git - if isDir then getGitFilesRegular git else getGitFilesForWorktree git + case (exists, isDir) of + (True, True) -> getGitFilesRegular git + (True, False) -> getGitFilesForWorktree git + (False, _) -> do + hPutStrLn stderr $ "Path " <> git <> " does not exists!" + pure [] -- | Get the 'GitInfo' for the given root directory. Root directory -- should be the directory containing the @.git@ directory.