Skip to content

Commit e5bb290

Browse files
committed
Improve acquiring logic
The first step of the acquiring logic (`acquire-git` and `acquire-repository` commands) is removing obsolete configuration options (keys). Now it consists of 2 steps: 1. removing of `elegant.acquired` key as it was replaced with `elegant-git.acquired` key 2. removing Elegant Git aliases as they should be reconfigured each time acquiring works Also, now the `libexec/plugins/configuration-acquired` plugin encapsulates acquiring logic.
1 parent 3c13059 commit e5bb290

9 files changed

Lines changed: 41 additions & 21 deletions

.workflows/ci-pipeline.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pipeline() {
1818
git config --global user.name "Elegant Git"
1919
git config --global user.email elegant.git@email.com
2020
git config --global core.editor vi
21-
git config --global elegant.acquired true
21+
git config --global elegant-git.acquired true
2222
./install.bash /usr/local src
2323
echo "'Unknown command' testing..."
2424
git elegant unknown-command | grep "Unknown command: git elegant unknown-command"

docs/configuration.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Windows with `true`
5353
6. `pull.rebase true` [`i`] uses `rebase` when `git pull`
5454
7. `rebase.autoStash false` [`i`] don't use `autostash` when `git rebase`
5555
8. `credential.helper osxkeychain` [`i`] configures default credentials storage on MacOS only
56-
9. `elegant.acquired true` [`g`] identifies that Elegant Git global configuration is applied
56+
9. `elegant-git.acquired true` [`g`] identifies that Elegant Git global configuration is applied
5757

5858
# Level: Aliases
5959

@@ -88,3 +88,5 @@ should be separarated with space). By default, `master` branch treats as protect
8888
means that Elegant Git commands for a branch state modification (such as `save-work`, `polish-work`,
8989
etc.) are prohibited to work if the current branch is protected. Also, the protected branches cannot
9090
be removed while running Elegant Git commands for serving a repository.
91+
- `elegant-git.acquired` defines whether a user was applied global configuration or not (see
92+
[approach](#approach) for the details).

libexec/git-elegant-acquire-git

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ MESSAGE
3131
default() {
3232
source ${BINS}/plugins/configuration
3333
source ${BINS}/plugins/configuration-protected-branches
34-
if ! $(is-acquired) ; then
34+
source ${BINS}/plugins/configuration-acquired
35+
obsolete-configurations-removing --global
36+
if ! is-git-acquired ; then
3537
info-box "Thank you for installing Elegant Git! Let's configure it..."
3638
cat <<MESSAGE
3739
Elegant Git aims to standardize how a work environment should be configured.
@@ -89,6 +91,5 @@ MESSAGE
8991
rebase_autoStash \
9092
credential_helper_darwin \
9193
acquired
92-
aliases-removing --global
9394
aliases-configuration --global $(git elegant show-commands)
9495
}

libexec/git-elegant-acquire-repository

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ MESSAGE
3232
default() {
3333
source ${BINS}/plugins/configuration
3434
source ${BINS}/plugins/configuration-protected-branches
35-
aliases-removing --local
35+
source ${BINS}/plugins/configuration-acquired
36+
obsolete-configurations-removing --local
3637
basics-configuration --local \
3738
user_name \
3839
user_email \
3940
core_editor \
4041
protected_branches
41-
if ! is-acquired ; then
42+
if ! is-git-acquired ; then
4243
standards-configuration --local \
4344
core_comment \
4445
apply_whitespace \

libexec/plugins/configuration

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ rebase_autoStash=("rebase.autoStash" "false")
3131
## Credentials, MAC only
3232
credential_helper_darwin=("credential.helper" "osxkeychain")
3333

34-
# Elegant Git
35-
acquired=("elegant.acquired" "true")
36-
3734
__ask_question() {
3835
# usage: __ask_options <prefix>
3936
# it makes available ANSWER available
@@ -102,7 +99,7 @@ aliases-removing() {
10299
local scope=${1}
103100
local aliases=($(git config ${scope} --name-only --get-regexp "^alias\." "^elegant ([-a-z]+)$"))
104101
if [[ ${#aliases[@]} -ne 0 ]]; then
105-
info-box "Removing old Elegant Git aliases..."
102+
info-text "Removing old Elegant Git aliases..."
106103
local counter=0
107104
for alias in ${aliases[@]}; do
108105
git-verbose config ${scope} --unset ${alias}
@@ -123,10 +120,14 @@ aliases-configuration() {
123120
done
124121
}
125122

126-
is-acquired() {
127-
# usage: if $(acquired-state) ; then
128-
if [[ "$(git config --global --get ${acquired[0]} || true)" == ${acquired[1]} ]]; then
129-
return 0
123+
obsolete-configurations-removing() {
124+
# usage: obsolete-configurations-removing <--global | --local>
125+
local scope=${1}
126+
info-box "Removing obsolete configurations..."
127+
local old_acquired="elegant.acquired"
128+
if git config ${scope} --get-regexp ${old_acquired} >/dev/null; then
129+
info-text "Removing old Elegnat Git configuration keys..."
130+
git-verbose config ${scope} --unset ${old_acquired}
130131
fi
131-
return 1
132+
aliases-removing ${scope}
132133
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
# The plugin provides configuration for "acquired" logic that determines
3+
# whether Elegant Git global configuration is applied or not.
4+
5+
acquired=("elegant-git.acquired" "true")
6+
7+
is-git-acquired() {
8+
# usage : is-git-acquired
9+
# result: 0 or 1
10+
if [[ "$(git config --global --get ${acquired[0]} || true)" == ${acquired[1]} ]]; then
11+
return 0
12+
fi
13+
return 1
14+
}

tests/git-elegant-acquire-git.bats

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ teardown() {
4444
[[ ${lines[@]} =~ "==>> git config --global core.autocrlf true" ]]
4545
[[ ${lines[@]} =~ "==>> git config --global pull.rebase true" ]]
4646
[[ ${lines[@]} =~ "==>> git config --global rebase.autoStash false" ]]
47-
[[ ${lines[@]} =~ "==>> git config --global elegant.acquired true" ]]
47+
[[ ${lines[@]} =~ "==>> git config --global elegant-git.acquired true" ]]
4848
# negative checks are used instead of checking commands size
4949
[[ ! ${lines[@]} =~ "==>> git config --global credential.helper osxkeychain" ]]
5050
[[ ! ${lines[@]} =~ "==>> git config --global core.autocrlf input" ]]
@@ -60,7 +60,7 @@ teardown() {
6060
[[ ${lines[@]} =~ "==>> git config --global core.autocrlf input" ]]
6161
[[ ${lines[@]} =~ "==>> git config --global pull.rebase true" ]]
6262
[[ ${lines[@]} =~ "==>> git config --global rebase.autoStash false" ]]
63-
[[ ${lines[@]} =~ "==>> git config --global elegant.acquired true" ]]
63+
[[ ${lines[@]} =~ "==>> git config --global elegant-git.acquired true" ]]
6464
# negative checks are used instead of checking commands size
6565
[[ ! ${lines[@]} =~ "==>> git config --global credential.helper osxkeychain" ]]
6666
[[ ! ${lines[@]} =~ "==>> git config --global core.autocrlf true" ]]
@@ -77,7 +77,7 @@ teardown() {
7777
[[ ${lines[@]} =~ "==>> git config --global pull.rebase true" ]]
7878
[[ ${lines[@]} =~ "==>> git config --global rebase.autoStash false" ]]
7979
[[ ${lines[@]} =~ "==>> git config --global credential.helper osxkeychain" ]]
80-
[[ ${lines[@]} =~ "==>> git config --global elegant.acquired true" ]]
80+
[[ ${lines[@]} =~ "==>> git config --global elegant-git.acquired true" ]]
8181
# negative checks are used instead of checking commands size
8282
[[ ! ${lines[@]} =~ "==>> git config --global core.autocrlf true" ]]
8383
}

tests/git-elegant-acquire-repository.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ teardown() {
111111
[[ ${lines[@]} =~ "2 Elegant Git aliases were removed." ]]
112112
}
113113

114-
@test "'acquire-repository': works properly if 'elegant.acquired' == true " {
114+
@test "'acquire-repository': works properly if 'elegant-git.acquired' == true " {
115115
fake-pass "uname -s" Linux
116116
repo git config --local "alias.aaa" "\"elegant aaa\""
117117
repo git config --global "alias.bbb" "\"elegant bbb\""
118-
repo git config --global "elegant.acquired" "true"
118+
repo git config --global "elegant-git.acquired" "true"
119119
repo git config --local core.editor my-text-editor
120120
check git-elegant acquire-repository
121121
[[ ${lines[@]} =~ "What is your user name? {Elegant Git}: " ]]

workflows

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ repository() {
3434
git config --global user.name \"Elegant Git\"
3535
git config --global user.email elegant.git@email.com
3636
git config --global core.editor vi
37-
git config --global elegant.acquired true
37+
git config --global elegant-git.protected-branches master
38+
git config --global elegant-git.acquired true
3839
./install.bash /usr/local src
3940
"
4041
info-text "Ready! Enjoy experiments..."

0 commit comments

Comments
 (0)