update for DiffTree change

This actually fixes a bug; if pre-commit was run in a subdir, it would pass
relative files when updating the associated file maps, and so the maps
wouldn't update.

I don't think this bug happened in practice, due to the way pre-commit is
called by the hook. It happened to chdir to the top of the work tree.
This commit is contained in:
Joey Hess 2013-10-17 14:52:12 -04:00
parent 7a9daefea2
commit 7206dcb376

View file

@ -16,6 +16,7 @@ import qualified Git.Ref
import Annex.CatFile
import Annex.Content.Direct
import Git.Sha
import Git.FilePath
def :: [Command]
def = [command "pre-commit" paramPaths seek SectionPlumbing
@ -40,10 +41,11 @@ startIndirect file = next $ do
startDirect :: [String] -> CommandStart
startDirect _ = next $ do
(diffs, clean) <- inRepo $ Git.DiffTree.diffIndex Git.Ref.headRef
forM_ diffs go
makeabs <- flip fromTopFilePath <$> gitRepo
forM_ diffs (go makeabs)
next $ liftIO clean
where
go diff = do
go makeabs diff = do
withkey (Git.DiffTree.srcsha diff) (Git.DiffTree.srcmode diff) removeAssociatedFile
withkey (Git.DiffTree.dstsha diff) (Git.DiffTree.dstmode diff) addAssociatedFile
where
@ -51,4 +53,5 @@ startDirect _ = next $ do
k <- catKey sha mode
case k of
Nothing -> noop
Just key -> void $ a key (Git.DiffTree.file diff)
Just key -> void $ a key $
makeabs $ Git.DiffTree.file diff