Re: Please default to 'commit -a' when no changes were added

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]