avoid pre-commit hook messing up new-style unlocked files in v6 repo
authorJoey Hess <joeyh@joeyh.name>
Wed, 9 Dec 2015 19:18:25 +0000 (15:18 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 9 Dec 2015 19:18:54 +0000 (15:18 -0400)
Annex/Version.hs
CmdLine/Seek.hs
Command/PreCommit.hs
doc/git-annex-pre-commit.mdwn

index f9b24d9c499533c13f4613bba490a83b22edd17c..4c2a990fa8dd649d4a5ef9718083fe34a7a87ca6 100644 (file)
@@ -43,6 +43,12 @@ versionSupportsDirectMode = go <$> getVersion
        go (Just "6") = False
        go _ = True
 
+versionSupportsUnlockedPointers :: Annex Bool
+versionSupportsUnlockedPointers = go <$> getVersion
+  where
+       go (Just "6") = True
+       go _ = False
+
 setVersion :: Version -> Annex ()
 setVersion = setConfig versionField
 
index 0b6cc1e781d559b9684005c19d324feda4578d97..48545ce042f7a4085161cdf6b9d393e84a6b813d 100644 (file)
@@ -115,7 +115,7 @@ withPairs a params = seekActions $ return $ map a $ pairs [] params
        pairs c (x:y:xs) = pairs ((x,y):c) xs
        pairs _ _ = error "expected pairs"
 
-withFilesToBeCommitted :: (String -> CommandStart) -> CmdParams -> CommandSeek
+withFilesToBeCommitted :: (FilePath -> CommandStart) -> CmdParams -> CommandSeek
 withFilesToBeCommitted a params = seekActions $ prepFiltered a $
        seekHelper LsFiles.stagedNotDeleted params
 
index 2d62b51f3f3788fc03991a51015a1507499149ac..b6f52d01c243f3e16844497ce1c2b0596c2bf7cd 100644 (file)
@@ -16,7 +16,9 @@ import qualified Command.Add
 import qualified Command.Fix
 import Annex.Direct
 import Annex.Hook
+import Annex.Link
 import Annex.View
+import Annex.Version
 import Annex.View.ViewedFile
 import Annex.LockFile
 import Logs.View
@@ -49,9 +51,14 @@ seek ps = lockPreCommitHook $ ifM isDirect
                                void $ liftIO cleanup
                        , do
                                -- fix symlinks to files being committed
-                               withFilesToBeCommitted (whenAnnexed Command.Fix.start) ps
+                               flip withFilesToBeCommitted ps $ \f -> 
+                                       maybe stop (Command.Fix.start f)
+                                               =<< isAnnexLink f
                                -- inject unlocked files into the annex
-                               withFilesUnlockedToBeCommitted startIndirect ps
+                               -- (not needed when repo version uses
+                               -- unlocked pointer files)
+                               unlessM versionSupportsUnlockedPointers $
+                                       withFilesUnlockedToBeCommitted startInjectUnlocked ps
                        )
                runAnnexHook preCommitAnnexHook
                -- committing changes to a view updates metadata
@@ -64,8 +71,8 @@ seek ps = lockPreCommitHook $ ifM isDirect
        )
        
 
-startIndirect :: FilePath -> CommandStart
-startIndirect f = next $ do
+startInjectUnlocked :: FilePath -> CommandStart
+startInjectUnlocked f = next $ do
        unlessM (callCommandAction $ Command.Add.start f) $
                error $ "failed to add " ++ f ++ "; canceling commit"
        next $ return True
index bc1e86e182b8a88736d25b16f1d0b41193fc5e65..21e5aef68f16f59de8d74c25d6ab37e5d2c0ef4e 100644 (file)
@@ -12,10 +12,14 @@ This is meant to be called from git's pre-commit hook. `git annex init`
 automatically creates a pre-commit hook using this.
 
 Fixes up symlinks that are staged as part of a commit, to ensure they
-point to annexed content. Also handles injecting changes to unlocked
-files into the annex. When in a view, updates metadata to reflect changes
+point to annexed content.
+
+When in a view, updates metadata to reflect changes
 made to files in the view.
 
+When in a repository that has not been upgraded to annex.version 6, 
+also handles injecting changes to unlocked files into the annex. 
+
 # SEE ALSO
 
 [[git-annex]](1)