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
|
@ -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
Add a link
Reference in a new issue