diff --git a/docs/commands.md b/docs/commands.md index fe71bbd..6de2d15 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -36,6 +36,7 @@ There are commands used in various situations such as and others commands Prints available Elegant Git commands. + acquire-git Configures a Git installation. Please visit https://elegant-git.bees-hive.org to find out more. @@ -72,6 +73,18 @@ git branch --delete --force __eg git push origin --delete task-123 ``` +# `acquire-git` + +```bash +usage: git elegant acquire-repository +``` + +Applies the "basics", "standards", and "aliases" configurations to the current +Git installation using `git config --global`. + +To find out what will be configured, please visit +https://elegant-git.bees-hive.org/en/latest/configuration/ + # `acquire-repository` ```bash diff --git a/docs/configuration.md b/docs/configuration.md index e8cdb4a..a4a1bb0 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1,14 +1,30 @@ # Approach Elegant Git aims to standardize how a Git repository should be configured. It operates 3 levels of -configurations (basics, standards, and aliases - see below) which are applied only within a -current Git repository by using `git config --local `. +configurations (basics, standards, and aliases - see below) which can be applied to a repository +(local configuration) or to a Git globally (global configuration). + +The local configuration applies by running +[`git elegant acquire-repository`](commands.md#acquire-repository) and configures current Git +repository by using `git config --local `. + +The global configuration invokes by [`git elegant acquire-git`](commands.md#acquire-git) and uses +`git config --global ` for Git configuration. + +If you've applied a global configuration, there is no sense to repeat some options for a local one. +That's why the following markers explain how each particular option will be configured: + +- `b` - configures for both configurations +- `l` - configures only for a local configuration +- `g` - configures only for a global configuration +- `i` - if a global configuration is applied, an option isn't used in local configuration; +otherwise, uses in local configuration # Basics The basics configuration configures the following options `git config` options: -1. `user.name` -2. `user.email` -3. `core.editor` +1. `user.name` (`b`) +2. `user.email` (`b`) +3. `core.editor` (`i`) During the configuration, you will be asked to provide appropriate values. @@ -17,21 +33,22 @@ The standards configuration configures a set of the `git config` options which b OS-specific configurations and add specific options for the correct execution of Elegant Git commands. It consists of -1. setting `core.commentChar` to `|` enables commit messages starting from `#` -2. setting `apply.whitespace` to `fix` removes whitespaces when applying a patch -3. setting `fetch.prune` to `true` keeps remote-tracking references up-to-date -4. setting `fetch.pruneTags` to `false` does not remove tags until you specify it explicitly +1. setting `core.commentChar` (`i`) to `|` enables commit messages starting from `#` +2. setting `apply.whitespace` (`i`) to `fix` removes whitespaces when applying a patch +3. setting `fetch.prune` (`i`) to `true` keeps remote-tracking references up-to-date +4. setting `fetch.pruneTags` (`i`) to `false` does not remove tags until you specify it explicitly (`git fetch --tags`) -5. setting `core.autocrlf` to either `input` on MacOS/Linux or `true` on Windows solves issues with +5. setting `core.autocrlf` (`i`) to either `input` on MacOS/Linux or `true` on Windows solves issues with line endings -6. setting `pull.rebase` to `true` uses `rebase` when `git pull` -7. setting `rebase.autoStash` to `false` uses `autostash` never when `git rebase` -8. setting `credential.helper` to `osxkeychain` on MacOS configures default credentials storage +6. setting `pull.rebase` (`i`) to `true` uses `rebase` when `git pull` +7. setting `rebase.autoStash` (`i`) to `false` uses `autostash` never when `git rebase` +8. setting `credential.helper` (`i`) to `osxkeychain` on MacOS configures default credentials storage +9. setting `elegant.acquired` (`g`) to `true` identifies that Elegant Git global configuration is applied # Aliases In order to make Elegant Git command like a native Git command, each Elegant Git command will have an appropriate alias like `git elegant save-work` will become `git save-work`. This should significantly improve user experience. -The configuration is a call of `git config "alias." "elegant "` for each Elegant +The configuration is a call of `git config "alias." "elegant "` (`i`) for each Elegant Git command. diff --git a/install.bash b/install.bash index a291f5a..ea31aed 100755 --- a/install.bash +++ b/install.bash @@ -62,12 +62,14 @@ main() { echo "Elegant Git is installed to '${INSTALL_PATH}/bin/git-elegant'." echo " The final step after installation is to run - git elegant acquire-repository -for each git repository where Elegant Git is going to be used. + git elegant acquire-git +to apply the latest Elegant Git's configuration. If this step is not completed, Elegant Git may behave unexpectedly since the desired Git configuration (relevant for the current version) -is not applied. +is not applied. Please read more on + https://elegant-git.bees-hive.org/en/latest/configuration/ + " command -v git-elegant 1>/dev/null 2>&1 || next-steps ${INSTALL_PATH} } diff --git a/libexec/git-elegant b/libexec/git-elegant index 2fed828..de490a2 100755 --- a/libexec/git-elegant +++ b/libexec/git-elegant @@ -127,6 +127,7 @@ $(--print-command-in-usage release-work) and others $(--print-command-in-usage commands) +$(--print-command-in-usage acquire-git) Please visit ${__site} to find out more. diff --git a/libexec/git-elegant-acquire-git b/libexec/git-elegant-acquire-git new file mode 100755 index 0000000..8b5d651 --- /dev/null +++ b/libexec/git-elegant-acquire-git @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +set -e + +command-purpose() { + cat < # it makes available ANSWER available diff --git a/tests/addons-repo.bash b/tests/addons-repo.bash index a890325..f6aa509 100644 --- a/tests/addons-repo.bash +++ b/tests/addons-repo.bash @@ -53,4 +53,7 @@ repo-clean() { if [[ -d "${GIT_REPO_DIR}" ]]; then rm -rf "${GIT_REPO_DIR}" fi + if [[ -f ~/.gitconfig ]]; then + rm -rf ~/.gitconfig + fi } diff --git a/tests/git-elegant-acquire-git.bats b/tests/git-elegant-acquire-git.bats new file mode 100644 index 0000000..069d630 --- /dev/null +++ b/tests/git-elegant-acquire-git.bats @@ -0,0 +1,95 @@ +#!/usr/bin/env bats + +load addons-common +load addons-read +load addons-fake +load addons-repo + +setup() { + repo-new +} + +teardown() { + fake-clean + repo-clean +} + +@test "'acquire-git': all configurations work as expected" { + check git-elegant acquire-git + [[ "${status}" -eq 0 ]] +} + +@test "'acquire-git': basics are configured as expected" { + check git-elegant acquire-git + [[ "${lines[@]}" =~ "What is your user name? {Elegant Git}: " ]] + [[ "${lines[@]}" =~ "==>> git config --global user.name Elegant Git" ]] + [[ "${lines[@]}" =~ "What is your user email? {elegant-git@example.com}: " ]] + [[ "${lines[@]}" =~ "==>> git config --global user.email elegant-git@example.com" ]] + [[ "${lines[@]}" =~ "Please specify a command to start the editor. {edi}: " ]] + [[ "${lines[@]}" =~ "==>> git config --global core.editor edi" ]] +} + +@test "'acquire-git': standards are configured as expected on Windows" { + fake-pass "uname -s" Windows + check git-elegant acquire-git + [[ "${lines[@]}" =~ "==>> git config --global core.commentChar |" ]] + [[ "${lines[@]}" =~ "==>> git config --global apply.whitespace fix" ]] + [[ "${lines[@]}" =~ "==>> git config --global fetch.prune true" ]] + [[ "${lines[@]}" =~ "==>> git config --global fetch.pruneTags false" ]] + [[ "${lines[@]}" =~ "==>> git config --global core.autocrlf true" ]] + [[ "${lines[@]}" =~ "==>> git config --global pull.rebase true" ]] + [[ "${lines[@]}" =~ "==>> git config --global rebase.autoStash false" ]] + [[ "${lines[@]}" =~ "==>> git config --global elegant.acquired true" ]] + # negative checks are used instead of checking commands size + [[ ! "${lines[@]}" =~ "==>> git config --global credential.helper osxkeychain" ]] + [[ ! "${lines[@]}" =~ "==>> git config --global core.autocrlf input" ]] +} + +@test "'acquire-git': standards are configured as expected on Linux" { + fake-pass "uname -s" Linux + check git-elegant acquire-git + [[ "${lines[@]}" =~ "==>> git config --global core.commentChar |" ]] + [[ "${lines[@]}" =~ "==>> git config --global apply.whitespace fix" ]] + [[ "${lines[@]}" =~ "==>> git config --global fetch.prune true" ]] + [[ "${lines[@]}" =~ "==>> git config --global fetch.pruneTags false" ]] + [[ "${lines[@]}" =~ "==>> git config --global core.autocrlf input" ]] + [[ "${lines[@]}" =~ "==>> git config --global pull.rebase true" ]] + [[ "${lines[@]}" =~ "==>> git config --global rebase.autoStash false" ]] + [[ "${lines[@]}" =~ "==>> git config --global elegant.acquired true" ]] + # negative checks are used instead of checking commands size + [[ ! "${lines[@]}" =~ "==>> git config --global credential.helper osxkeychain" ]] + [[ ! "${lines[@]}" =~ "==>> git config --global core.autocrlf true" ]] +} + +@test "'acquire-git': standards are configured as expected on Darwin" { + fake-pass "uname -s" Darwin + check git-elegant acquire-git + [[ "${lines[@]}" =~ "==>> git config --global core.commentChar |" ]] + [[ "${lines[@]}" =~ "==>> git config --global apply.whitespace fix" ]] + [[ "${lines[@]}" =~ "==>> git config --global fetch.prune true" ]] + [[ "${lines[@]}" =~ "==>> git config --global fetch.pruneTags false" ]] + [[ "${lines[@]}" =~ "==>> git config --global core.autocrlf input" ]] + [[ "${lines[@]}" =~ "==>> git config --global pull.rebase true" ]] + [[ "${lines[@]}" =~ "==>> git config --global rebase.autoStash false" ]] + [[ "${lines[@]}" =~ "==>> git config --global credential.helper osxkeychain" ]] + [[ "${lines[@]}" =~ "==>> git config --global elegant.acquired true" ]] + # negative checks are used instead of checking commands size + [[ ! "${lines[@]}" =~ "==>> git config --global core.autocrlf true" ]] +} + +@test "'acquire-git': new aliases are configured as expected" { + check git-elegant acquire-git + for next in $(git-elegant commands); do + echo "Test aliasing of '${next}' command" + [[ "${lines[@]}" =~ "==>> git config --global alias.${next} elegant ${next}" ]] + echo "Tested successfully!" + done +} + +@test "'acquire-git': old aliases remove correctly if they are present" { + repo git config --global "alias.aaa" "\"elegant aaa\"" + repo git config --global "alias.bbb" "\"elegant bbb\"" + check git-elegant acquire-git + [[ "$status" -eq 0 ]] + [[ "${lines[@]}" =~ "2 Elegant Git aliases were removed." ]] +} diff --git a/tests/git-elegant-acquire-repository.bats b/tests/git-elegant-acquire-repository.bats index e86f7d7..b4b629b 100644 --- a/tests/git-elegant-acquire-repository.bats +++ b/tests/git-elegant-acquire-repository.bats @@ -90,3 +90,20 @@ teardown() { [[ "$status" -eq 0 ]] [[ "${lines[@]}" =~ "2 Elegant Git aliases were removed." ]] } + +@test "'acquire-repository': 'elegant.acquired' affects configuration correctly" { + fake-pass "uname -s" Linux + repo git config --local "alias.aaa" "\"elegant aaa\"" + repo git config --global "alias.bbb" "\"elegant bbb\"" + repo git config --global "elegant.acquired" "true" + check git-elegant acquire-repository + [[ "${lines[@]}" =~ "What is your user name? {Elegant Git}: " ]] + [[ "${lines[@]}" =~ "==>> git config --local user.name Elegant Git" ]] + [[ "${lines[@]}" =~ "What is your user email? {elegant-git@example.com}: " ]] + [[ "${lines[@]}" =~ "==>> git config --local user.email elegant-git@example.com" ]] + [[ ! "${lines[@]}" =~ "Please specify a command to start the editor. {edi}: " ]] + [[ ! "${lines[@]}" =~ "==>> git config --local core.editor edi" ]] + [[ ! "${lines[@]}" =~ "==>> git config --local core.commentChar |" ]] + [[ "${lines[@]}" =~ "1 Elegant Git aliases were removed." ]] + [[ ! "${lines[@]}" =~ "==>> git config --local alias.acquire-repository elegant acquire-repository" ]] +} diff --git a/tests/git-elegant-commands.bats b/tests/git-elegant-commands.bats index 5690f56..828d02e 100644 --- a/tests/git-elegant-commands.bats +++ b/tests/git-elegant-commands.bats @@ -10,6 +10,7 @@ teardown() { @test "'commands': print all available commands" { COMMANDS=( "acquire-repository" + "acquire-git" "clone-repository" "init-repository" "start-work"