assistant, undo: When committing, let the usual git commit hooks run
Was doing a Git.Branch.commit for historical reasons to do with direct mode, which no longer apply. Note that the preCommitAnnexHook is no longer called in commitStaged because git-annex installs a pre-commit hook that runs the pre-commit-annex hook. And git commit will run the pre-commit hook. Sponsored-by: the NIH-funded NICEMAN (ReproNim TR&D3) project
This commit is contained in:
parent
b2027da251
commit
21123ba368
5 changed files with 77 additions and 10 deletions
|
@ -9,6 +9,8 @@ git-annex (10.20240130) UNRELEASED; urgency=medium
|
||||||
already downloaded files when yt-dlp or a special remote was used.
|
already downloaded files when yt-dlp or a special remote was used.
|
||||||
* addurl, importfeed: Added --raw-except option.
|
* addurl, importfeed: Added --raw-except option.
|
||||||
* stack.yaml: Update to lts-22.9 and use crypton.
|
* stack.yaml: Update to lts-22.9 and use crypton.
|
||||||
|
* assistant, undo: When committing, let the usual git commit
|
||||||
|
hooks run.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Mon, 29 Jan 2024 15:59:33 -0400
|
-- Joey Hess <id@joeyh.name> Mon, 29 Jan 2024 15:59:33 -0400
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,6 @@ import qualified Annex
|
||||||
import qualified Annex.Branch
|
import qualified Annex.Branch
|
||||||
import qualified Remote
|
import qualified Remote
|
||||||
import qualified Types.Remote as Remote
|
import qualified Types.Remote as Remote
|
||||||
import Annex.Hook
|
|
||||||
import qualified Git.Command
|
import qualified Git.Command
|
||||||
import qualified Git.LsFiles as LsFiles
|
import qualified Git.LsFiles as LsFiles
|
||||||
import qualified Git.Branch
|
import qualified Git.Branch
|
||||||
|
@ -431,15 +430,12 @@ commitMsg = do
|
||||||
return $ "git-annex in " ++ maybe "unknown" fromUUIDDesc (M.lookup u m)
|
return $ "git-annex in " ++ maybe "unknown" fromUUIDDesc (M.lookup u m)
|
||||||
|
|
||||||
commitStaged :: Git.Branch.CommitMode -> String -> Annex Bool
|
commitStaged :: Git.Branch.CommitMode -> String -> Annex Bool
|
||||||
commitStaged commitmode commitmessage = do
|
commitStaged commitmode commitmessage =
|
||||||
runAnnexHook preCommitAnnexHook
|
inRepo $ Git.Branch.commitCommand commitmode
|
||||||
mb <- inRepo Git.Branch.currentUnsafe
|
(Git.Branch.CommitQuiet True)
|
||||||
let (getparent, branch) = case mb of
|
[ Param "-m"
|
||||||
Just b -> (Git.Ref.sha b, b)
|
, Param commitmessage
|
||||||
Nothing -> (Git.Ref.headSha, Git.Ref.headRef)
|
]
|
||||||
parents <- maybeToList <$> inRepo getparent
|
|
||||||
void $ inRepo $ Git.Branch.commit commitmode False commitmessage branch parents
|
|
||||||
return True
|
|
||||||
|
|
||||||
mergeLocal :: [Git.Merge.MergeConfig] -> SyncOptions -> CurrBranch -> CommandStart
|
mergeLocal :: [Git.Merge.MergeConfig] -> SyncOptions -> CurrBranch -> CommandStart
|
||||||
mergeLocal mergeconfig o currbranch = stopUnless (notOnlyAnnex o) $
|
mergeLocal mergeconfig o currbranch = stopUnless (notOnlyAnnex o) $
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
[[!comment format=mdwn
|
||||||
|
username="joey"
|
||||||
|
subject="""comment 1"""
|
||||||
|
date="2024-02-07T18:59:34Z"
|
||||||
|
content="""
|
||||||
|
Re the default messages, let's just say that any choice git-annex makes
|
||||||
|
about a default commit message will not be to some people's liking.
|
||||||
|
|
||||||
|
Re the hook not being run, this is due to it using `git commit-tree`.
|
||||||
|
As well as being used for commits to the git-annex branch, it's also
|
||||||
|
used in a few other places, including `git-annex import`, and
|
||||||
|
generating adjusted branches and view branches, and the assistant
|
||||||
|
and `git-annex undo`.
|
||||||
|
"""]]
|
|
@ -0,0 +1,39 @@
|
||||||
|
[[!comment format=mdwn
|
||||||
|
username="joey"
|
||||||
|
subject="""comment 2"""
|
||||||
|
date="2024-02-07T19:09:44Z"
|
||||||
|
content="""
|
||||||
|
Git has two hooks, prepare-commit-msg and commit-msg. prepare-commit-msg
|
||||||
|
is used prior to interactive editing of the commit message. Since these
|
||||||
|
commits do not involve interactive editing, I don't think it
|
||||||
|
necesarily makes sense for git-annex to use that hook.
|
||||||
|
|
||||||
|
The commit-msg hook is simpler, and it would certianly be possible for
|
||||||
|
git-annex to call it everywhere it does a `git commit-tree`.
|
||||||
|
|
||||||
|
But if git-annex called either of these hooks, how is the hook supposed to
|
||||||
|
know what is being committed? In the usual case, the hook
|
||||||
|
is called with `GIT_INDEX_FILE` pointed at an index file that
|
||||||
|
has been modified to include whatever is going to be in the commit
|
||||||
|
(which may be different than what is staged in the index), and it knows
|
||||||
|
that the working directory is being committed. So it can
|
||||||
|
do things like `git diff --name-stage --cached` to get the files that
|
||||||
|
are being committed, for example.
|
||||||
|
|
||||||
|
In the git-annex case, `GIT_INDEX_FILE` is pointed at .git/annex/index
|
||||||
|
when committing the git-annex branch. If a commit-msg hook uses
|
||||||
|
`git diff --name-stage --cached`, it will diff from the working directory
|
||||||
|
to new git-annex branch contents, which will not be a useful set of file changes
|
||||||
|
to summarize in a commit message!
|
||||||
|
|
||||||
|
Even if the hook somehow knows that the git-annex branch is being
|
||||||
|
committed, the best it could do is diff from git-annex branch to
|
||||||
|
`GIT_INDEX_FILE` and then it has a bunch of git-annex branch filenames
|
||||||
|
that have changed, and is supposed to somehow generate a useful commit
|
||||||
|
message from that. How?
|
||||||
|
|
||||||
|
It seems more likely to me that you know that git-annex branch changes are
|
||||||
|
associated with an operation, so you might commit with "added 57 photos"
|
||||||
|
to the master branch, and then use the same message for the git-annex
|
||||||
|
branch commit. annex.commitmessage seems to already cover that case though?
|
||||||
|
"""]]
|
|
@ -0,0 +1,16 @@
|
||||||
|
[[!comment format=mdwn
|
||||||
|
username="joey"
|
||||||
|
subject="""comment 3"""
|
||||||
|
date="2024-02-07T19:58:11Z"
|
||||||
|
content="""
|
||||||
|
Irrespective of comment #2, I do think that it makes sense for the
|
||||||
|
assistant and `git-annex undo`, when committing to the HEAD branch,
|
||||||
|
to run all the usual commit hooks.
|
||||||
|
|
||||||
|
Actually, I don't see any reason for those to not run `git commit`.
|
||||||
|
It seems that the use of `git commit-tree` in those dates back to
|
||||||
|
[[!commit 03932212ecb8940e0fe2dd09c04951990bc29422]] which involved
|
||||||
|
direct mode.
|
||||||
|
|
||||||
|
Fixed those to run commits in the usual way (though noninteractive).
|
||||||
|
"""]]
|
Loading…
Reference in a new issue