diff --git a/Annex/Branch.hs b/Annex/Branch.hs index 8f927a78b4..42942d886f 100644 --- a/Annex/Branch.hs +++ b/Annex/Branch.hs @@ -500,11 +500,19 @@ append jl f appendable toappend = do {- Commit message used when making a commit of whatever data has changed - to the git-annex branch. -} commitMessage :: Annex String -commitMessage = fromMaybe "update" . annexCommitMessage <$> Annex.getGitConfig +commitMessage = fromMaybe "update" <$> getCommitMessage {- Commit message used when creating the branch. -} createMessage :: Annex String -createMessage = fromMaybe "branch created" . annexCommitMessage <$> Annex.getGitConfig +createMessage = fromMaybe "branch created" <$> getCommitMessage + +getCommitMessage :: Annex (Maybe String) +getCommitMessage = do + config <- Annex.getGitConfig + case annexCommitMessageCommand config of + Nothing -> return (annexCommitMessage config) + Just cmd -> catchDefaultIO (annexCommitMessage config) $ + Just <$> liftIO (readProcess "sh" ["-c", cmd]) {- Stages the journal, and commits staged changes to the branch. -} commit :: String -> Annex () diff --git a/CHANGELOG b/CHANGELOG index 8057fb3c81..e4d178c408 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,7 @@ git-annex (10.20240130) UNRELEASED; urgency=medium * stack.yaml: Update to lts-22.9 and use crypton. * assistant, undo: When committing, let the usual git commit hooks run. + * Added annex.commitmessage-command config. -- Joey Hess Mon, 29 Jan 2024 15:59:33 -0400 diff --git a/Types/GitConfig.hs b/Types/GitConfig.hs index f9e0149ddb..f97ee52192 100644 --- a/Types/GitConfig.hs +++ b/Types/GitConfig.hs @@ -88,6 +88,7 @@ data GitConfig = GitConfig , annexAlwaysCommit :: Bool , annexAlwaysCompact :: Bool , annexCommitMessage :: Maybe String + , annexCommitMessageCommand :: Maybe String , annexMergeAnnexBranches :: Bool , annexDelayAdd :: Maybe Int , annexHttpHeaders :: [String] @@ -176,6 +177,7 @@ extractGitConfig configsource r = GitConfig , annexAlwaysCommit = getbool (annexConfig "alwayscommit") True , annexAlwaysCompact = getbool (annexConfig "alwayscompact") True , annexCommitMessage = getmaybe (annexConfig "commitmessage") + , annexCommitMessageCommand = getmaybe (annexConfig "commitmessage-command") , annexMergeAnnexBranches = getbool (annexConfig "merge-annex-branches") True , annexDelayAdd = getmayberead (annexConfig "delayadd") , annexHttpHeaders = getlist (annexConfig "http-headers") diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index c4bd2b8df3..9d61e675a1 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -1088,6 +1088,11 @@ repository, using [[git-annex-config]]. See its man page for a list.) This works well in combination with annex.alwayscommit=false, to gather up a set of changes and commit them with a message you specify. +* `annex.commitmessage-command` + + This command is run and its output is used as the commit message to the + git-annex branch. + * `annex.alwayscompact` By default, git-annex compacts data it records in the git-annex branch. diff --git a/doc/todo/make_annex___34__respect__34___.git__47__hooks__47__prepare-commit-msg/comment_6_b8bb9e5c7156e4defd7a2e8b7777e1ba._comment b/doc/todo/make_annex___34__respect__34___.git__47__hooks__47__prepare-commit-msg/comment_6_b8bb9e5c7156e4defd7a2e8b7777e1ba._comment new file mode 100644 index 0000000000..4aa985a935 --- /dev/null +++ b/doc/todo/make_annex___34__respect__34___.git__47__hooks__47__prepare-commit-msg/comment_6_b8bb9e5c7156e4defd7a2e8b7777e1ba._comment @@ -0,0 +1,18 @@ +[[!comment format=mdwn + username="joey" + 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. + +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. + +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. +"""]]