Skip to content

Commit

Permalink
Add amend-work command
Browse files Browse the repository at this point in the history
This commit implement issue #125
Add comand amend-work to amend changes also add test for
amend-work command
  • Loading branch information
alexbeatnik committed Aug 20, 2019
1 parent 8138793 commit 4df04b6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
14 changes: 14 additions & 0 deletions libexec/git-elegant-amend-work
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -e

default(){
local BRANCH=$(__branches 'git branch | grep \*')
if [[ "$BRANCH" == "master" ]]; then
box "No commits to 'master' branch. Please read more on ${__site}"
box "Try 'git elegant start-work' prior to retrying this command."
exit 42
fi
boxtee git add --interactive
boxtee git diff --cached --check
boxtee git commit --amend
}
1 change: 1 addition & 0 deletions libexec/git-elegant-commands
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ default() {
echo "obtain-work"
echo "clear-local"
echo "commands"
echo "amend-work"
}
31 changes: 31 additions & 0 deletions tests/git-elegant-amend-work.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bats

load addons-common
load addons-fake
load addons-read
load addons-git

setup() {
init-repo
}

teardown() {
clean-fake
clean-git
}

@test "'amend-work': command works as expected for non-master branch" {
fake-pass git "add --interactive"
fake-pass git "diff --cached --check"
fake-pass git "commit --amend"
gitrepo git checkout -b test
check git-elegant amend-work
[[ "${status}" -eq 0 ]]
}

@test "'amend-work': exit code is 42 when current local branch is master" {
check git-elegant amend-work
[[ "${status}" -eq 42 ]]
[[ "${lines[@]}" =~ "== No commits to 'master' branch. Please read more on https://elegant-git.bees-hive.org ==" ]]
[[ "${lines[@]}" =~ "== Try 'git elegant start-work' prior to retrying this command. ==" ]]
}
3 changes: 2 additions & 1 deletion tests/git-elegant-commands.bats
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ teardown() {
"obtain-work"
"clear-local"
"commands"
"amend-work"
)
check git-elegant commands
for command in {0..12}; do
[ "${lines[$command]}" = "${COMMANDS[$command]}" ]
done
[ ${#lines[@]} -eq 10 ]
[ ${#lines[@]} -eq 11 ]
}

@test "'commands': default exit code is 0" {
Expand Down

0 comments on commit 4df04b6

Please sign in to comment.