From 9935c2dec74028e1f85b8ac6f2fde02f5c8bd686 Mon Sep 17 00:00:00 2001 From: Dmytro Serdiuk Date: Sun, 29 Apr 2018 20:28:25 +0300 Subject: [PATCH] Display git command before execute it #107 --- CONTRIBUTING.md | 30 +++++++++++--------------- docs/README.md | 4 +++- src/main/git-elegant | 13 +++++++++++ src/main/git-elegant-add | 2 +- src/main/git-elegant-check | 10 ++++----- src/main/git-elegant-clone | 2 +- src/main/git-elegant-configure | 4 ++-- src/main/git-elegant-feature | 10 ++++----- src/main/git-elegant-init | 4 ++-- src/main/git-elegant-pull | 6 +++--- src/main/git-elegant-push | 2 +- src/main/git-elegant-push-after-rebase | 4 ++-- src/main/git-elegant-rebase | 4 ++-- src/test/git-elegant-check.bats | 4 ++-- src/test/git-elegant-configure.bats | 18 ++++++++-------- 15 files changed, 63 insertions(+), 54 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7e19961..d0b7d46 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,19 +1,17 @@ -Usage -===== -Installation ------------- +# Coding rules +- use `boxtee` to execute each original `git` command + +# Usage +## Installation Use `./install.bash dev` to get an installation from the current sources. -Debug mode ----------- +## Debug mode Use `export GED=1` to switch on the debug of `git elegant` or `unset GED` to switch off. -Unit tests -========== +# Unit tests [bats](https://github.com/sstephenson/bats) is used for unit testing. -Addons ------- +## Addons Add the following line to the test file if the extension is required: - `load addons-common` to have the working test (**mandatory**) - `load addons-git` to interact with real git repository (**optional**) @@ -21,24 +19,20 @@ Add the following line to the test file if the extension is required: - `load addons-cd` to fake `cd` command (**optional**) - `load addons-read` to fake `read` command (**optional**) -Writing tests -------------- +## Writing tests 1. **Use `setup()` or `teardown()`** bats methods only in the tests. 2. Use **`check` instead of bats `run`** to execute a command to be tested. 3. If `addons-fake` or `addons-git` is used, call `clean-fake` or `clean-git` within a `teardown()` method. -Assertions ----------- +## Assertions - `[ "${lines[0]}" = "+ the space " ]` for a output line (index starts from 0) - `[ "$status" -eq 2 ]` for a command status - `[ "${#lines[@]}" -eq 0 ]` for an empty command output -Test name template ------------------- +## Test name template Use the following test name template - `'': ` like `'check -s': trailing spaces in the staged changes`. -Run ---- +## Run Use one of the following commands to run the unit tests: - `bats src/test` - `./run-tests` diff --git a/docs/README.md b/docs/README.md index 253a728..40d87bb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,8 @@ Elegant git =========== -Your `git` experience will be changed forever. +`git elegant` is a `git` extension which allows simplifying of `git` interaction. + +`git elegant` always says which original git command will be executed. Philosophy ---------- diff --git a/src/main/git-elegant b/src/main/git-elegant index bc9659a..912c9f7 100755 --- a/src/main/git-elegant +++ b/src/main/git-elegant @@ -9,6 +9,19 @@ __green=`tput setaf 2` __magenta=`tput setaf 5` __reset=`tput sgr0` +box(){ + t="$@xxxxxx" + c=${replace:-=} + echo ${t//?/$c} + echo "$c$c $@ $c$c" + echo ${t//?/$c} +} + +boxtee() { + box "$@" + "$@" +} + __gm() { echo "${__green}$@${__reset}" } diff --git a/src/main/git-elegant-add b/src/main/git-elegant-add index f3c3876..88e8de6 100644 --- a/src/main/git-elegant-add +++ b/src/main/git-elegant-add @@ -6,5 +6,5 @@ default() { __gm "There are candidates to be added to commit:" __loop "__gm -" ${FILES[@]} __batch "Do you want to add all of them?" "Add this?" "git add" ${FILES[@]} - git status + boxtee git status } diff --git a/src/main/git-elegant-check b/src/main/git-elegant-check index 54771a3..bbfe7c5 100644 --- a/src/main/git-elegant-check +++ b/src/main/git-elegant-check @@ -4,16 +4,16 @@ set -e default() { case "$1" in "-a" | "--all") - git diff --check - git diff --cached --check + boxtee git diff --check + boxtee git diff --cached --check ;; "-u" | "--unstaged") - git diff --check + boxtee git diff --check ;; "-s" | "--staged") - git diff --cached --check + boxtee git diff --cached --check ;; - *) git elegant check --all + *) boxtee git elegant check --all ;; esac } diff --git a/src/main/git-elegant-clone b/src/main/git-elegant-clone index 66767f6..d5f6582 100644 --- a/src/main/git-elegant-clone +++ b/src/main/git-elegant-clone @@ -3,7 +3,7 @@ set -e default() { _validate "$1" "Cloneable URL" - git clone "$1" + boxtee git clone "$1" cd $(basename -s .git $1) git elegant configure --local } diff --git a/src/main/git-elegant-configure b/src/main/git-elegant-configure index 6baac60..16fa4d6 100755 --- a/src/main/git-elegant-configure +++ b/src/main/git-elegant-configure @@ -42,12 +42,12 @@ _configure() { for com in $(git elegant commands); do alias="e${com}" command="elegant $com" - git config $MODE $(eval "echo -n \$${f}_key\$alias") "$command" + boxtee git config $MODE $(eval "echo -n \$${f}_key\$alias") "$command" done fi else if [ -n "${answer}" ]; then - git config $MODE $(eval "echo -n \$${f}_key") "$answer" + boxtee git config $MODE $(eval "echo -n \$${f}_key") "$answer" fi fi done diff --git a/src/main/git-elegant-feature b/src/main/git-elegant-feature index a3ee485..5596a25 100644 --- a/src/main/git-elegant-feature +++ b/src/main/git-elegant-feature @@ -3,12 +3,12 @@ set -e default() { _validate "$1" "Feature name" - status=$(git stash save elegant-git) - git elegant pull $MASTER - git checkout -b "$1" + status=$(boxtee git stash save elegant-git) + boxtee git elegant pull $MASTER + boxtee git checkout -b "$1" if [[ "$status" =~ "Saved working directory" ]]; then - git stash apply stash^{/elegant-git} - git stash drop stash@{0} + boxtee git stash apply stash^{/elegant-git} + boxtee git stash drop stash@{0} fi } diff --git a/src/main/git-elegant-init b/src/main/git-elegant-init index 6516a50..735548e 100755 --- a/src/main/git-elegant-init +++ b/src/main/git-elegant-init @@ -2,6 +2,6 @@ set -e default() { - git init - git elegant configure --local + boxtee git init + boxtee git elegant configure --local } diff --git a/src/main/git-elegant-pull b/src/main/git-elegant-pull index d159061..3b17b1a 100644 --- a/src/main/git-elegant-pull +++ b/src/main/git-elegant-pull @@ -3,8 +3,8 @@ set -e default() { if [ -n "$1" ]; then - git checkout "$1" + boxtee git checkout "$1" fi - git fetch --tags - git pull + boxtee git fetch --tags + boxtee git pull } diff --git a/src/main/git-elegant-push b/src/main/git-elegant-push index 0d29876..137a694 100644 --- a/src/main/git-elegant-push +++ b/src/main/git-elegant-push @@ -3,5 +3,5 @@ set -e default() { local BRANCH=$(__branches 'git branch | grep \*') - git push -u origin $BRANCH:$BRANCH + boxtee git push -u origin $BRANCH:$BRANCH } diff --git a/src/main/git-elegant-push-after-rebase b/src/main/git-elegant-push-after-rebase index 0658e28..846eec3 100644 --- a/src/main/git-elegant-push-after-rebase +++ b/src/main/git-elegant-push-after-rebase @@ -2,6 +2,6 @@ set -e default() { - git elegant rebase - git elegant push + boxtee git elegant rebase + boxtee git elegant push } diff --git a/src/main/git-elegant-rebase b/src/main/git-elegant-rebase index 37c00f2..18c7336 100644 --- a/src/main/git-elegant-rebase +++ b/src/main/git-elegant-rebase @@ -2,6 +2,6 @@ set -e default() { - git fetch --tags - git rebase $RMASTER + boxtee git fetch --tags + boxtee git rebase $RMASTER } diff --git a/src/test/git-elegant-check.bats b/src/test/git-elegant-check.bats index 287f890..2d8ce11 100644 --- a/src/test/git-elegant-check.bats +++ b/src/test/git-elegant-check.bats @@ -55,13 +55,13 @@ preconditions() { init-repo && add-st-change "no space" check git-elegant check -s [ "$status" -eq 0 ] - [ "${#lines[@]}" -eq 0 ] + [ "${#lines[@]}" -eq 3 ] } @test "'check': trailing spaces in the staged changes" { init-repo && add-st-change "the space " check git-elegant check -s [ "$status" -eq 2 ] - [ "${lines[1]}" = "+the space " ] + [ "${lines[4]}" = "+the space " ] } \ No newline at end of file diff --git a/src/test/git-elegant-configure.bats b/src/test/git-elegant-configure.bats index b86f202..c8ec083 100644 --- a/src/test/git-elegant-configure.bats +++ b/src/test/git-elegant-configure.bats @@ -51,19 +51,19 @@ teardown() { fake-preconditions check git-elegant configure --global [ "${lines[0]}" = "your user name [UserName]: " ] - [ "${lines[1]}" = "your user email [UserEmail]: " ] - [ "${lines[2]}" = "commit message won't start with [|]: " ] - [ "${lines[3]}" = "whitespace issues on patching [fix]: " ] - [ "${lines[4]}" = "add git aliases for all 'elegant git' commands [yes]: " ] - [ ${#lines[@]} -eq 5 ] + [ "${lines[4]}" = "your user email [UserEmail]: " ] + [ "${lines[8]}" = "commit message won't start with [|]: " ] + [ "${lines[12]}" = "whitespace issues on patching [fix]: " ] + [ "${lines[16]}" = "add git aliases for all 'elegant git' commands [yes]: " ] + [ ${#lines[@]} -eq 17 ] } @test "'configure': sequence of the local git configuration is correct" { init-repo check git-elegant configure --local [ "${lines[0]}" = "your user name [Elegant Git]: " ] - [ "${lines[1]}" = "your user email [elegant-git@example.com]: " ] - [ "${lines[2]}" = "commit message won't start with [|]: " ] - [ "${lines[3]}" = "whitespace issues on patching [fix]: " ] - [ ${#lines[@]} -eq 4 ] + [ "${lines[4]}" = "your user email [elegant-git@example.com]: " ] + [ "${lines[8]}" = "commit message won't start with [|]: " ] + [ "${lines[12]}" = "whitespace issues on patching [fix]: " ] + [ ${#lines[@]} -eq 16 ] }