summaryrefslogtreecommitdiff
path: root/src/Repo.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2025-06-28 09:16:17 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2025-06-28 09:16:17 +0200
commita9ca7d47f22b37c43ac97f1f04181fe114f3ce58 (patch)
tree832557703035691d0ed492192fa4daa866d03661 /src/Repo.hs
parentbdd1d73969ff9015f444239099ed4cdd6afff910 (diff)
Fix extrating subtree hash in a bare repository
Changelog: Fix getting (sub)directory in a bare repository
Diffstat (limited to 'src/Repo.hs')
-rw-r--r--src/Repo.hs22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/Repo.hs b/src/Repo.hs
index 98178e6..b154209 100644
--- a/src/Repo.hs
+++ b/src/Repo.hs
@@ -280,15 +280,19 @@ getCommitMessage = fmap commitMessage . getCommitDetails
getSubtree :: (MonadIO m, MonadFail m) => Maybe Commit -> FilePath -> Tree -> m Tree
getSubtree mbCommit path tree = liftIO $ do
let GitRepo {..} = treeRepo tree
- readProcessWithExitCode "git" [ "--git-dir=" <> gitDir, "rev-parse", "--verify", "--quiet", showTreeId (treeId tree) <> ":./" <> path <> "/" ] "" >>= \case
- ( ExitSuccess, out, _ ) | tid : _ <- lines out -> do
- return Tree
- { treeRepo = treeRepo tree
- , treeId = TreeId (BC.pack tid)
- , treeSubdir = treeSubdir tree </> path
- }
- _ -> do
- fail $ "subtree ‘" <> path <> "’ not found" <> maybe "" ((" in revision ‘" <>) . (<> "’") . showCommitId . commitId) mbCommit
+ dirs = dropWhile (`elem` [ ".", "/" ]) $ splitDirectories path
+
+ case dirs of
+ [] -> return tree
+ _ -> readProcessWithExitCode "git" [ "--git-dir=" <> gitDir, "rev-parse", "--verify", "--quiet", showTreeId (treeId tree) <> ":" <> joinPath dirs ] "" >>= \case
+ ( ExitSuccess, out, _ ) | tid : _ <- lines out -> do
+ return Tree
+ { treeRepo = treeRepo tree
+ , treeId = TreeId (BC.pack tid)
+ , treeSubdir = joinPath $ treeSubdir tree : dirs
+ }
+ _ -> do
+ fail $ "subtree ‘" <> path <> "’ not found" <> maybe "" ((" in revision ‘" <>) . (<> "’") . showCommitId . commitId) mbCommit
checkoutAt :: (MonadIO m, MonadFail m) => Tree -> FilePath -> m ()