Skip to content

Commit

Permalink
Display git command before execute it
Browse files Browse the repository at this point in the history
  • Loading branch information
extsoft committed Apr 29, 2018
1 parent d6af6a3 commit 9935c2d
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 54 deletions.
30 changes: 12 additions & 18 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,38 @@
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**)
- `load addons-fake` to fake a Linux command (**optional**)
- `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 - `'<command args>': <describe what will be tested>` 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`
Expand Down
4 changes: 3 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -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
----------
Expand Down
13 changes: 13 additions & 0 deletions src/main/git-elegant
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/git-elegant-add
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 5 additions & 5 deletions src/main/git-elegant-check
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion src/main/git-elegant-clone
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions src/main/git-elegant-configure
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/main/git-elegant-feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions src/main/git-elegant-init
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
set -e

default() {
git init
git elegant configure --local
boxtee git init
boxtee git elegant configure --local
}
6 changes: 3 additions & 3 deletions src/main/git-elegant-pull
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion src/main/git-elegant-push
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions src/main/git-elegant-push-after-rebase
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
set -e

default() {
git elegant rebase
git elegant push
boxtee git elegant rebase
boxtee git elegant push
}
4 changes: 2 additions & 2 deletions src/main/git-elegant-rebase
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
set -e

default() {
git fetch --tags
git rebase $RMASTER
boxtee git fetch --tags
boxtee git rebase $RMASTER
}
4 changes: 2 additions & 2 deletions src/test/git-elegant-check.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 " ]

}
18 changes: 9 additions & 9 deletions src/test/git-elegant-configure.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 [[email protected]]: " ]
[ "${lines[2]}" = "commit message won't start with [|]: " ]
[ "${lines[3]}" = "whitespace issues on patching [fix]: " ]
[ ${#lines[@]} -eq 4 ]
[ "${lines[4]}" = "your user email [[email protected]]: " ]
[ "${lines[8]}" = "commit message won't start with [|]: " ]
[ "${lines[12]}" = "whitespace issues on patching [fix]: " ]
[ ${#lines[@]} -eq 16 ]
}

0 comments on commit 9935c2d

Please sign in to comment.