diff --git a/git-pair b/git-pair index 9eb1a22..e181b27 100755 --- a/git-pair +++ b/git-pair @@ -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) } diff --git a/tests/pairing_with_names.bats b/tests/pairing_with_names.bats index d8a8154..b096de7 100644 --- a/tests/pairing_with_names.bats +++ b/tests/pairing_with_names.bats @@ -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'" {