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

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

 



Jonathan Nieder <jrnieder@xxxxxxxxx> writes:

> 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; }

Thanks. That is the missing test.

> 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).

Because with the above test it knows when -a is wrong and won't use it.

>> 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

Must have overlooked that mail, sorry.
--
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]