* Unexpected behavior when git-adding files in a pre-commit hook then using "git commit -o"
@ 2015-05-04 12:33 Michaël Fortin
2015-05-04 18:03 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: Michaël Fortin @ 2015-05-04 12:33 UTC (permalink / raw)
To: git
Hi,
I’ve encountered unexpected behavior performing a git add from a pre-commit hook, followed by performing a commit using the “-o” flag, providing a pathspec. Here is a small bash script that explains the issue and serves as a repro:
###############
echo "----> Setup a new test repo"
dir_name="PreCommitHookAddTest"
rm -rf $dir_name; mkdir $dir_name; cd $dir_name
git init; git commit --allow-empty -m "Initial commit"
echo "----> Add a pre-commit hook that stages a file that doesn't currently exist in the repo"
echo "touch auto-added; git add auto-added" > .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
echo "----> Try committing a new file using the '-o' flag"
touch manually-added; git add manually-added
git commit -o -m "Commit that ran the pre-commit hook and should contain file 'auto-added'" -- manually-added
echo "----> Results (expected: working copy clean; actual: auto-added is reported as both DELETED and UNTRACKED. HEAD and working copy are the same, staging area contains ‘incorrect' state)"
git status
echo "----> Stage the file after the fact"
git add auto-added
echo "----> Notice that the working copy is now clean"
git status
###############
I would like to avoid the above-described “invalid” state by performing operations correctly in my pre-commit hook, rather than having to add a post-commit hook only to perform a “git add” after the fact (which the repro script emulates); it seems like an ugly workaround to me.
I have had similar issues before, which Jeff King kindly resolved here:
http://thread.gmane.org/gmane.comp.version-control.git/263319/focus=263323
The provided solution does not seem to help in this new context, or at least I cannot make sense of it in relation to this issue, with my limited knowledge of Git internals.
Any insight would be appreciated!
Thanks in advance,
Michaël Fortin
www.irradiated.net
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-05-04 18:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-04 12:33 Unexpected behavior when git-adding files in a pre-commit hook then using "git commit -o" Michaël Fortin
2015-05-04 18:03 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).