pre-commit: Avoid committing the git-annex branch
Except when a commit is made in a view, which changes metadata. Make the assistant commit the git-annex branch after git commit of working tree changes. This allows using the annex.commitmessage-command in the assistant to generate a commit message for the git-annex branch that relies on state gathered during the commit of the working tree. Eg, it might reuse the commit message. Note that, when not using the assistant, a git-annex add still commits the git-annex branch, so such a annex.commitmessage-command set up would not work then. But if someone is using the assistant and wants programmatic control over commit messages, this is useful. Someone not using the assistant can get the same result by using annex.alwayscommit=false during the git-annex add, and git-annex merge after they git commit. pre-commit was never really intended to commit the git-annex branch (except after recording changed metadata), but the assistant did sort of rely on it. It does later commit the git-annex branch before pushing to remotes, but I didn't want to risk building up lots of uncommitted changes to it if that didn't happen frequently. Sponsored-by: the NIH-funded NICEMAN (ReproNim TR&D3) project
This commit is contained in:
parent
68e99513f0
commit
3475b09c3e
5 changed files with 52 additions and 17 deletions
|
@ -1,6 +1,6 @@
|
|||
{- git-annex assistant commit thread
|
||||
-
|
||||
- Copyright 2012-2023 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2012-2024 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
@ -19,7 +19,6 @@ import Assistant.TransferQueue
|
|||
import Assistant.Drop
|
||||
import Types.Transfer
|
||||
import Logs.Location
|
||||
import qualified Annex.Queue
|
||||
import Utility.ThreadScheduler
|
||||
import qualified Utility.Lsof as Lsof
|
||||
import qualified Utility.DirWatcher as DirWatcher
|
||||
|
@ -35,6 +34,8 @@ import Annex.InodeSentinal
|
|||
import Annex.CurrentBranch
|
||||
import Annex.FileMatcher
|
||||
import qualified Annex
|
||||
import qualified Annex.Queue
|
||||
import qualified Annex.Branch
|
||||
import Utility.InodeCache
|
||||
import qualified Database.Keys
|
||||
import qualified Command.Sync
|
||||
|
@ -248,6 +249,11 @@ commitStaged msg = do
|
|||
]
|
||||
when ok $
|
||||
Command.Sync.updateBranches =<< getCurrentBranch
|
||||
{- Commit the git-annex branch. This comes after
|
||||
- the commit of the staged changes, so that
|
||||
- annex.commitmessage-command can examine that
|
||||
- commit. -}
|
||||
Annex.Branch.commit =<< Annex.Branch.commitMessage
|
||||
return ok
|
||||
|
||||
{- If there are PendingAddChanges, or InProcessAddChanges, the files
|
||||
|
|
|
@ -12,6 +12,8 @@ git-annex (10.20240130) UNRELEASED; urgency=medium
|
|||
* assistant, undo: When committing, let the usual git commit
|
||||
hooks run.
|
||||
* Added annex.commitmessage-command config.
|
||||
* pre-commit: Avoid committing the git-annex branch
|
||||
(except when a commit is made in a view, which changes metadata).
|
||||
|
||||
-- Joey Hess <id@joeyh.name> Mon, 29 Jan 2024 15:59:33 -0400
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{- git-annex command
|
||||
-
|
||||
- Copyright 2010-2014 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2010-2024 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
@ -20,12 +20,14 @@ import Logs.View
|
|||
import Logs.MetaData
|
||||
import Types.View
|
||||
import Types.MetaData
|
||||
import qualified Annex
|
||||
import qualified Annex.Branch
|
||||
|
||||
import qualified Data.Set as S
|
||||
import qualified Data.Text as T
|
||||
|
||||
cmd :: Command
|
||||
cmd = command "pre-commit" SectionPlumbing
|
||||
cmd = noCommit $ command "pre-commit" SectionPlumbing
|
||||
"run by git pre-commit hook"
|
||||
paramPaths
|
||||
(withParams seek)
|
||||
|
@ -47,9 +49,14 @@ seek ps = do
|
|||
-- committing changes to a view updates metadata
|
||||
currentView >>= \case
|
||||
Nothing -> noop
|
||||
Just (v, _madj) -> withViewChanges
|
||||
(addViewMetaData v)
|
||||
(removeViewMetaData v)
|
||||
Just (v, _madj) -> do
|
||||
withViewChanges
|
||||
(addViewMetaData v)
|
||||
(removeViewMetaData v)
|
||||
-- Manually commit in this case, because
|
||||
-- noCommit prevents automatic commit.
|
||||
whenM (annexAlwaysCommit <$> Annex.getGitConfig) $
|
||||
Annex.Branch.commit =<< Annex.Branch.commitMessage
|
||||
|
||||
addViewMetaData :: View -> ViewedFile -> Key -> CommandStart
|
||||
addViewMetaData v f k = starting "metadata" ai si $
|
||||
|
|
|
@ -134,3 +134,5 @@ Date: Fri Feb 2 12:06:41 2024 -0500
|
|||
|
||||
[[!meta author=yoh]]
|
||||
[[!tag projects/repronim]]
|
||||
|
||||
> [[done]] --[[Joey]]
|
||||
|
|
|
@ -3,16 +3,34 @@
|
|||
subject="""comment 6"""
|
||||
date="2024-02-12T17:36:32Z"
|
||||
content="""
|
||||
Turns out that the assistant doesn't commit to the git-annex branch itself,
|
||||
instead the pre-commit hook runs `git-annex pre-commit`, and
|
||||
the git-annex branch commit on process shutdown is where the commit
|
||||
happens.
|
||||
I've implemented annex.commitmessage-command and made sure that the
|
||||
assistant calls it after committing the working tree changes.
|
||||
|
||||
A bit surprising! If the pre-commit hook didn't run git-annex,
|
||||
the assistant would later explicitly commit the branch before
|
||||
pushing to remotes.
|
||||
Example of using the prepare-commit-msg hook to generate a commit message
|
||||
and then reusing that message for the git-annex branch commit:
|
||||
|
||||
Anyway, this does mean you can rely on the git-annex branch commit
|
||||
happening after the working tree commit. At least, when there are
|
||||
no other git-annex processes running.
|
||||
joey@darkstar:~/tmp/a>cat .git/hooks/prepare-commit-msg
|
||||
#!/bin/sh
|
||||
msg="files: $(git diff --name-only --cached)"
|
||||
echo $msg > .git/last-commit-msg
|
||||
echo $msg > $1
|
||||
|
||||
joey@darkstar:~/tmp/a>git config annex.commitmessage-command
|
||||
cat .git/last-commit-msg
|
||||
|
||||
joey@darkstar:~/tmp/a>git-annex assistant
|
||||
joey@darkstar:~/tmp/a>date > bar
|
||||
|
||||
joey@darkstar:~/tmp/a>git log -n1 master
|
||||
commit 676f87d02f031192c7eb0b7d29a6ce2429b8c727 (HEAD -> master, synced/master)
|
||||
Author: Joey Hess <joeyh@joeyh.name>
|
||||
Date: Mon Feb 12 14:29:12 2024 -0400
|
||||
|
||||
files: bar
|
||||
joey@darkstar:~/tmp/a>git log -n1 git-annex
|
||||
commit 676588dd6d921115782e61be85f75e395cc480b6 (git-annex)
|
||||
Author: Joey Hess <joeyh@joeyh.name>
|
||||
Date: Mon Feb 12 14:29:12 2024 -0400
|
||||
|
||||
files: bar
|
||||
"""]]
|
||||
|
|
Loading…
Add table
Reference in a new issue