git post-checkout and post-merge hooks
* init, upgrade: Install git post-checkout and post-merge hooks that run git annex smudge --update. * precommit: Run git annex smudge --update, because the post-merge hook is not run when there is a merge conflict. So the work tree will be updated when a commit is made to resolve the merge conflict. * precommit: Run git annex smudge --update, because the post-merge hook is not run when there is a merge conflict. So the work tree will be updated when a commit is made to resolve the merge conflict. * Note that git has no hooks run after git stash or git cherry-pick, so the user will have to manually run git annex smudge --update after such commands. Nothing currently installs the hooks into v6 repos that already exist. Something will need to be done about that, either move this behavior to v7, or document that the user will need to manually fix up their v6 repos. This commit was sponsored by Eric Drechsel on Patreon.
This commit is contained in:
parent
917a2c6095
commit
ca7de61454
6 changed files with 43 additions and 6 deletions
|
@ -32,6 +32,17 @@ postReceiveHook = Git.Hook "post-receive"
|
||||||
[ mkHookScript "git annex post-receive"
|
[ mkHookScript "git annex post-receive"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
postCheckoutHook :: Git.Hook
|
||||||
|
postCheckoutHook = Git.Hook "post-checkout" smudgeHook []
|
||||||
|
|
||||||
|
postMergeHook :: Git.Hook
|
||||||
|
postMergeHook = Git.Hook "post-merge" smudgeHook []
|
||||||
|
|
||||||
|
-- Only run git-annex smudge --update when git-annex supports it.
|
||||||
|
-- Older versions of git-annex didn't need this hook.
|
||||||
|
smudgeHook :: String
|
||||||
|
smudgeHook = mkHookScript "if git annex smudge --update >/dev/null 2>&1; then git-annex smudge --update; fi"
|
||||||
|
|
||||||
preCommitAnnexHook :: Git.Hook
|
preCommitAnnexHook :: Git.Hook
|
||||||
preCommitAnnexHook = Git.Hook "pre-commit-annex" "" []
|
preCommitAnnexHook = Git.Hook "pre-commit-annex" "" []
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,9 @@ initialize' ai mversion = checkCanInitialize ai $ do
|
||||||
whenM versionSupportsUnlockedPointers $ do
|
whenM versionSupportsUnlockedPointers $ do
|
||||||
configureSmudgeFilter
|
configureSmudgeFilter
|
||||||
scanUnlockedFiles
|
scanUnlockedFiles
|
||||||
|
unlessM isBareRepo $ do
|
||||||
|
hookWrite postCheckoutHook
|
||||||
|
hookWrite postMergeHook
|
||||||
checkAdjustedClone >>= \case
|
checkAdjustedClone >>= \case
|
||||||
NeedUpgradeForAdjustedClone ->
|
NeedUpgradeForAdjustedClone ->
|
||||||
void $ upgrade True versionForAdjustedClone
|
void $ upgrade True versionForAdjustedClone
|
||||||
|
|
|
@ -26,6 +26,14 @@ git-annex (6.20181012) UNRELEASED; urgency=medium
|
||||||
honor annex.thin. Now git annex smudge --update has to be run
|
honor annex.thin. Now git annex smudge --update has to be run
|
||||||
after a checkout to update unlocked files in the working tree
|
after a checkout to update unlocked files in the working tree
|
||||||
with annexed file contents.
|
with annexed file contents.
|
||||||
|
* init, upgrade: Install git post-checkout and post-merge hooks that run
|
||||||
|
git annex smudge --update.
|
||||||
|
* precommit: Run git annex smudge --update, because the post-merge
|
||||||
|
hook is not run when there is a merge conflict. So the work tree will
|
||||||
|
be updated when a commit is made to resolve the merge conflict.
|
||||||
|
* Note that git has no hooks run after git stash or git cherry-pick,
|
||||||
|
so the user will have to manually run git annex smudge --update
|
||||||
|
after such commands.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Sat, 13 Oct 2018 00:52:02 -0400
|
-- Joey Hess <id@joeyh.name> Sat, 13 Oct 2018 00:52:02 -0400
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import Command
|
||||||
import Config
|
import Config
|
||||||
import qualified Command.Add
|
import qualified Command.Add
|
||||||
import qualified Command.Fix
|
import qualified Command.Fix
|
||||||
|
import qualified Command.Smudge
|
||||||
import Annex.Direct
|
import Annex.Direct
|
||||||
import Annex.Hook
|
import Annex.Hook
|
||||||
import Annex.Link
|
import Annex.Link
|
||||||
|
@ -54,11 +55,21 @@ seek ps = lockPreCommitHook $ ifM isDirect
|
||||||
flip withFilesToBeCommitted l $ \f -> commandAction $
|
flip withFilesToBeCommitted l $ \f -> commandAction $
|
||||||
maybe stop (Command.Fix.start Command.Fix.FixSymlinks f)
|
maybe stop (Command.Fix.start Command.Fix.FixSymlinks f)
|
||||||
=<< isAnnexLink f
|
=<< isAnnexLink f
|
||||||
|
ifM versionSupportsUnlockedPointers
|
||||||
|
-- after a merge conflict or git
|
||||||
|
-- cherry-pick or stash, pointer
|
||||||
|
-- files in the worktree won't
|
||||||
|
-- be populated, so populate them
|
||||||
|
-- here
|
||||||
|
( Command.Smudge.updateSmudged
|
||||||
|
-- When there's a false index,
|
||||||
|
-- restaging the files won't work.
|
||||||
|
. Restage =<< liftIO Git.haveFalseIndex
|
||||||
-- inject unlocked files into the annex
|
-- inject unlocked files into the annex
|
||||||
-- (not needed when repo version uses
|
-- (not needed when repo version uses
|
||||||
-- unlocked pointer files)
|
-- unlocked pointer files)
|
||||||
unlessM versionSupportsUnlockedPointers $
|
, withFilesOldUnlockedToBeCommitted (commandAction . startInjectUnlocked) l
|
||||||
withFilesOldUnlockedToBeCommitted (commandAction . startInjectUnlocked) l
|
)
|
||||||
)
|
)
|
||||||
runAnnexHook preCommitAnnexHook
|
runAnnexHook preCommitAnnexHook
|
||||||
-- committing changes to a view updates metadata
|
-- committing changes to a view updates metadata
|
||||||
|
|
|
@ -67,7 +67,7 @@ smudge file = do
|
||||||
Just k -> do
|
Just k -> do
|
||||||
topfile <- inRepo (toTopFilePath file)
|
topfile <- inRepo (toTopFilePath file)
|
||||||
Database.Keys.addAssociatedFile k topfile
|
Database.Keys.addAssociatedFile k topfile
|
||||||
smudgeLog k topfile
|
void $ smudgeLog k topfile
|
||||||
liftIO $ B.putStr b
|
liftIO $ B.putStr b
|
||||||
stop
|
stop
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import Annex.Direct
|
||||||
import Annex.Content
|
import Annex.Content
|
||||||
import Annex.CatFile
|
import Annex.CatFile
|
||||||
import Annex.WorkTree
|
import Annex.WorkTree
|
||||||
|
import Annex.Hook
|
||||||
import qualified Database.Keys
|
import qualified Database.Keys
|
||||||
import qualified Annex.Content.Direct as Direct
|
import qualified Annex.Content.Direct as Direct
|
||||||
import qualified Git
|
import qualified Git
|
||||||
|
@ -63,6 +64,9 @@ upgrade automatic = do
|
||||||
- adjust branch. Instead, update HEAD manually. -}
|
- adjust branch. Instead, update HEAD manually. -}
|
||||||
inRepo $ setHeadRef b
|
inRepo $ setHeadRef b
|
||||||
configureSmudgeFilter
|
configureSmudgeFilter
|
||||||
|
unlessM isBareRepo $ do
|
||||||
|
hookWrite postCheckoutHook
|
||||||
|
hookWrite postMergeHook
|
||||||
-- Inode sentinal file was only used in direct mode and when
|
-- Inode sentinal file was only used in direct mode and when
|
||||||
-- locking down files as they were added. In v6, it's used more
|
-- locking down files as they were added. In v6, it's used more
|
||||||
-- extensively, so make sure it exists, since old repos that didn't
|
-- extensively, so make sure it exists, since old repos that didn't
|
||||||
|
|
Loading…
Reference in a new issue