-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
acquire-repository
command
First of all, `acquire-repository` is a former `configure-repository` command with several improvements: 1. We aks user only about name and email. All other configurations have to be set by default as it provides us full control on user repository. 2. Aliases are installed for local repository only. And we don't install aliases which have to be applied only once (like init, acquire-repository, etc.). Second, `testtee` command is introduced along with recommendations for its usage.
- Loading branch information
Showing
14 changed files
with
193 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env bash | ||
#set -e | ||
|
||
_user_name_key="user.name" | ||
_user_name_default=$(git config "$_user_name_key" || echo '') | ||
_user_name_message="What is your user name?" | ||
|
||
_user_email_key="user.email" | ||
_user_email_default=$(git config "$_user_email_key" || echo '') | ||
_user_email_message="What is your user email?" | ||
|
||
_core_comment_char_key="core.commentChar" | ||
_core_comment_char_default="|" | ||
|
||
_apply_whitespace_key="apply.whitespace" | ||
_apply_whitespace_default="fix" | ||
|
||
__ask_question() { | ||
# usage: __ask_options <prefix> | ||
# it makes available ANSWER available | ||
message=$(eval "echo -n \$${1}_message") | ||
echo -n "$message" | ||
default=$(eval "echo -n \$${1}_default") | ||
if [[ -n "$default" ]]; then echo -n " {$default}"; fi | ||
echo -n ": " | ||
read answer | ||
export ANSWER=${answer:-$default} | ||
} | ||
|
||
__interactive-configuration() { | ||
FUNCTIONS=$@ | ||
for f in ${FUNCTIONS[@]}; do | ||
unset ANSWER | ||
while [ -z "${ANSWER}" ]; do | ||
__ask_question ${f} | ||
if [[ -n "${ANSWER}" ]]; then | ||
boxtee git config --local $(eval "echo -n \$${f}_key") "${ANSWER}" | ||
fi | ||
done | ||
done | ||
} | ||
|
||
__mandatory-configuration() { | ||
FUNCTIONS=$@ | ||
for config in ${FUNCTIONS[@]}; do | ||
key=$(eval "echo -n \$${config}_key") | ||
value=$(eval "echo -n \$${config}_default") | ||
boxtee git config --local ${key} ${value} | ||
done | ||
} | ||
__remove-old-aliases() { | ||
old_aliases=($(git config --get-regexp ^alias\. | grep "elegant " | cut -f 1 -d " ")) | ||
if [[ ${#old_aliases[@]} -ne 0 ]]; then | ||
for old in ${old_aliases[@]}; do | ||
git config --local --unset ${old} | ||
done | ||
box "${#old_aliases[@]} git aliases were removed that contained 'elegant git' reference." | ||
else | ||
box "There are no git aliases which contain 'elegant git' reference." | ||
fi | ||
} | ||
|
||
__aliases-configuration() { | ||
for command in ${@}; do | ||
local alias=${command} | ||
local origin="elegant ${command}" | ||
boxtee git config --local "alias.${alias}" "${origin}" | ||
done | ||
} | ||
|
||
default() { | ||
__interactive-configuration _user_name _user_email | ||
__mandatory-configuration _core_comment_char _apply_whitespace | ||
__remove-old-aliases | ||
__aliases-configuration "pull" "clear-local" $(git elegant commands | grep work) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,5 @@ set -e | |
|
||
default() { | ||
boxtee git init | ||
git elegant configure-repository | ||
git elegant acquire-repository | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,37 +4,28 @@ set -e | |
GIT_REPO_DIR="/tmp/elegant-git-repo" | ||
FILE_TO_MODIFY=file | ||
|
||
_gilog(){ | ||
echo "$(basename ${BASH_SOURCE[0]}): $@" | ||
} | ||
|
||
_ex() { | ||
_gilog "$@" | ||
eval "$@" | ||
} | ||
|
||
init-repo() { | ||
if [ -n "$GIT_REPO_DIR" ]; then | ||
_ex mkdir -p $GIT_REPO_DIR | ||
_ex cd $GIT_REPO_DIR | ||
_ex git init | ||
_ex git config --local user.email "\"[email protected]\"" | ||
_ex git config --local user.name "\"Elegant Git\"" | ||
_ex touch $FILE_TO_MODIFY | ||
_ex git add . | ||
_ex git commit -m "\"Add $FILE_TO_MODIFY\"" | ||
testtee mkdir -p $GIT_REPO_DIR | ||
testtee cd $GIT_REPO_DIR | ||
testtee git init | ||
testtee git config --local user.email "\"[email protected]\"" | ||
testtee git config --local user.name "\"Elegant Git\"" | ||
testtee touch $FILE_TO_MODIFY | ||
testtee git add . | ||
testtee git commit -m "\"Add $FILE_TO_MODIFY\"" | ||
else | ||
exit 1 | ||
fi | ||
} | ||
|
||
add-unst-change(){ | ||
_ex "echo -e \"$@\" >> $FILE_TO_MODIFY" | ||
testtee "echo -e \"$@\" >> $FILE_TO_MODIFY" | ||
} | ||
|
||
add-st-change(){ | ||
add-unst-change "$@" | ||
_ex git add $FILE_TO_MODIFY | ||
testtee git add $FILE_TO_MODIFY | ||
} | ||
|
||
clean-git() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env bats | ||
|
||
load addons-common | ||
load addons-read | ||
load addons-fake | ||
load addons-git | ||
|
||
fake-preconditions() { | ||
fake-pass git "config user.name" "UserName" | ||
fake-pass git "config user.email" "UserEmail" | ||
|
||
} | ||
setup() { | ||
init-repo | ||
} | ||
|
||
teardown() { | ||
clean-fake | ||
clean-git | ||
} | ||
|
||
@test "'acquire-repository': all configurations work as expected" { | ||
check git-elegant acquire-repository | ||
[[ ${#lines[@]} -eq 35 ]] | ||
[[ "${status}" -eq 0 ]] | ||
} | ||
|
||
@test "'acquire-repository': interactive configuration works as expected" { | ||
check git-elegant acquire-repository | ||
[[ "${lines[@]}" =~ "What is your user name? {Elegant Git}: " ]] | ||
[[ "${lines[@]}" =~ "What is your user email? {[email protected]}: " ]] | ||
} | ||
|
||
@test "'acquire-repository': mandatory configuration works as expected" { | ||
check git-elegant acquire-repository | ||
[[ "${lines[@]}" =~ "== git config --local core.commentChar | ==" ]] | ||
[[ "${lines[@]}" =~ "== git config --local apply.whitespace fix ==" ]] | ||
} | ||
|
||
@test "'acquire-repository': aliases configuration works as expected" { | ||
check git-elegant acquire-repository | ||
[[ "${lines[@]}" =~ "== git config --local alias.start-work elegant start-work ==" ]] | ||
[[ "${lines[@]}" =~ "== git config --local alias.save-work elegant save-work ==" ]] | ||
[[ "${lines[@]}" =~ "== git config --local alias.deliver-work elegant deliver-work ==" ]] | ||
[[ "${lines[@]}" =~ "== git config --local alias.accept-work elegant accept-work ==" ]] | ||
} | ||
|
||
@test "'acquire-repository': removing existing git aliases works as expected when aliases available" { | ||
testtee git config --local "alias.aaa" "\"elegant aaa\"" | ||
testtee git config --local "alias.bbb" "\"elegant bbb\"" | ||
check git-elegant acquire-repository | ||
[[ "$status" -eq 0 ]] | ||
[[ "${lines[@]}" =~ "== 2 git aliases were removed that contained 'elegant git' reference. ==" ]] | ||
} | ||
|
||
@test "'acquire-repository': removing existing git aliases works as expected when aliases are absent" { | ||
check git-elegant acquire-repository | ||
[[ "${status}" -eq 0 ]] | ||
[[ "${lines[@]}" =~ "== There are no git aliases which contain 'elegant git' reference. ==" ]] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.