Re: Please default to 'commit -a' when no changes were added
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Apr 24, 2010, 21:40 UTC
- Message-ID
- <20100424214024.GA8044@progeny.tock>
- In-Reply-To
- <8739yktuvs.fsf@frosties.localdomain>
Hi again,
Goswin von Brederlow wrote:
> so far two people have suggested an alias > for this and both have completly failed to achived the desired result.
I had thought Adam already suggested using ‘git diff-index --cached --quiet HEAD’ [1].
You can do so like this:
cat <<-EOF >$HOME/bin/git-ci #!/bin/sh cleanindex() { git diff-index --cached --quiet HEAD; }
if test "$1" != "-h" then echo >&2 usage: git ci && exit 129 fi if test "$#" != 0 then echo >&2 Please use git commit directly. if cleanindex then echo >&2 '(no staged changes)' else git diff --cached --name-status fi exit 129 fi if cleanindex then exec git commit -a else exec git commit fi EOF chmod +x $HOME/bin/git-ci
But dense as I am, I still can’t imagine why
echo '[alias] ci = commit -a' >>$HOME/.gitconfig
wouldn’t be better in every way (especially if Jakub’s commit.preserveindex is enabled).
> If you know of a test to check if an index exists or not, preferably one > that does consider new files being added or files being removed as > "index exists", then please do speak up.
test -e .git/index
I know, not what you meant. But the condition you are looking for is “staged content does not match the last commit”, not “the tool has suddenly entered a different mode”.
Hope that helps, Jonathan
[1] Well, he did: http://thread.gmane.org/gmane.linux.debian.devel.bugs.general/698001/focus=145581