Skip to content

Commit

Permalink
Sorts author names instead of just appending them
Browse files Browse the repository at this point in the history
By keeping pair names sorted, whenever you pair with the same people you
should get the same author. Prior, the first author in the list was
always the author's machine which could make the same pair yield
different author name results depending on the machine being used to
produce the commits.

The lines to sort authors are a mess, that is why I was delaying this.
As a remind to myself, this is what they do:

* Echoes final author name with all pairs.
* Uses `tr` to change "+" into new lines.
* Uses `sed` to remove leading white spaces from author names.
* Uses `sed` to remove trailing white spaces from author names.
* Sorts all author names available.
* Uses `tr` to change new lines back to "+".
* Uses `sed` to remove trailing "+" form end of the line.
* Uses `sed` to add spaces before and after "+".

I am not proud of it but I made sure that this works on Linuxes and BSDs
(OSX).
  • Loading branch information
augustohp committed Feb 1, 2016
1 parent 9a4c98c commit 67a0f1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 13 additions & 3 deletions git-pair
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,19 @@ function gp_add_author()
CURRENT_AUTHORS=$(git config user.name)
[[ $( echo $CURRENT_AUTHORS | grep -e "$PAIR_NAME" ) != "" ]] && { echo "Author '$PAIR_NAME' already in list!"; exit 102; }

PAIR_NAMES="${CURRENT_AUTHORS} ${PAIR_SEPARATOR} ${PAIR_NAME}"

git config --local user.name "$PAIR_NAMES"
ORDERED_PAIR_NAMES_ONELINE=$(
echo "${CURRENT_AUTHORS} ${PAIR_SEPARATOR} ${PAIR_NAME}" |
tr ${PAIR_SEPARATOR} '\n' |
sed 's/^ //g' |
sed 's/ $//g' |
sort |
tr '\n' ${PAIR_SEPARATOR} |
sed "s/${PAIR_SEPARATOR}$//g" |
sed "s/${PAIR_SEPARATOR}/ ${PAIR_SEPARATOR} /g"
)


git config --local user.name "$ORDERED_PAIR_NAMES_ONELINE"
echo "Local authors name now are:" $(git config --local user.name)
}

Expand Down
4 changes: 2 additions & 2 deletions tests/pairing_with_names.bats
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ load git_environment
assert_equals "Local authors name now are: Git Pair User + John Doe" "$output"
}

@test "Pairing with two other user names" {
@test "Pairing with two other user names order them alphabetically" {
run git-pair "John Doe"
run git-pair "Jane Doe"

assert_success
assert_equals "Local authors name now are: Git Pair User + John Doe + Jane Doe" "$output"
assert_equals "Local authors name now are: Git Pair User + Jane Doe + John Doe" "$output"
}

@test "Ending a pairing session with 'ended'" {
Expand Down

0 comments on commit 67a0f1a

Please sign in to comment.