Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add signing #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
$ wget https://raw.github.com/roylines/gits/master/gits.sh -O /usr/local/bin/gits
$ chmod ugo+x /usr/local/bin/gits
$ gits
44 changes: 37 additions & 7 deletions gits.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
# set -e
config="$HOME/.gits"

if [ ! -f $config ];
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"