diff --git a/README.md b/README.md index f410923..c4705fe 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ To find all options use: gits --help -The first time you use gits it will prompt for git usernames and emails for the pair of developers. This is stored in ~/.gits and this file can safely removed to reset pairing. +The first time you use gits it will prompt for git usernames (spaces are allowed) and emails for the pair of developers. This is stored in ~/.gits and this file can safely removed to reset pairing. Although you only need to use gits when committing to repositories, you can use it instead of git for all operations if you prefer. @@ -21,8 +21,11 @@ If you want to take the random element out of a commit you can force the author gits 1 commit -m 'forcing the commit to the first user in the .gits file' gits 2 commit -m 'forcing the commit to the second user in the .gits file' +## Signing key +When git config user.signingkey is set, gits will automatically try to commit with -S when the first user is the author. + ## Installation ### Manual Installation - $ sudo wget https://raw.github.com/roylines/gits/master/gits.sh -O /usr/local/bin/gits - $ sudo chmod ugo+x /usr/local/bin/gits - $ gits \ No newline at end of file + $ wget https://raw.github.com/roylines/gits/master/gits.sh -O /usr/local/bin/gits + $ chmod ugo+x /usr/local/bin/gits + $ gits diff --git a/gits.sh b/gits.sh index d235fea..a30adcb 100755 --- a/gits.sh +++ b/gits.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -e +# set -e config="$HOME/.gits" if [ ! -f $config ]; @@ -14,8 +14,10 @@ then echo "Please enter the second pair email > " read email2 - echo "$username1 $email1" > $config - echo "$username2 $email2" >> $config + echo "$username1" > $config + echo "$email1" >> $config + echo "$username2" >> $config + echo "$email2" >> $config echo "created config for: $username1 ($email1), $username2 ($email2)" exit 0 @@ -26,16 +28,21 @@ n=$(( r %= 2 )) if [ $1 = "1" ]; then - echo 'forcing author to first user' + echo ' >>>> forcing author to first user' shift + n=1 fi if [ $1 = "2" ]; then - echo 'forcing author to second user' + echo ' >>>> forcing author to second user' shift + n=2 fi +old_IFS=$IFS +IFS=$'\n' + filecontent=( `cat "$config" `) if [ $n -eq 1 ] then @@ -50,6 +57,29 @@ else export GIT_AUTHOR_EMAIL=${filecontent[1]} fi -git "$@" +IFS=$old_IFS + +if [ "$1" = "commit" ] +then + SIGNED=( `git config user.signingkey` ) + if [ -z "$SIGNED" ] + then + echo " >>>> Your commit will not be signed, no signing key!" + SIGNED_COMMAND='' + else + if [ $n -eq 1 ] + then + echo " >>>> Your commit will be signed!" + SIGNED_COMMAND='-S' + else + echo " >>>> Your commit will not be signed, only signing the first author!" + SIGNED_COMMAND='' + fi + fi + git "$@" $SIGNED_COMMAND +else + git "$@" +fi -echo "commit: $GIT_COMMITTER_NAME, author: $GIT_AUTHOR_NAME" +echo " >>>> commit name: $GIT_COMMITTER_NAME, email: $GIT_COMMITTER_EMAIL" +echo " >>>> author name: $GIT_AUTHOR_NAME, email: $GIT_AUTHOR_EMAIL"