Skip to content

Commit

Permalink
Introduce save-work command
Browse files Browse the repository at this point in the history
This command is a former `save` command.

Also, this change updates 'tests/git-elegant-commands.bats' test by
extracting all commands to an array and iteration over it while making
the assertions.

`git elegant check --staged` is replaced with
`git diff --cached --check` as `check` command will be deprecated soon.
  • Loading branch information
extsoft committed Jul 21, 2019
1 parent aa2fc0b commit 9b50cf8
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 27 deletions.
17 changes: 14 additions & 3 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ git pull
git checkout -b <branch-name>
```

# `save-work`
Saves available changes (or a part of them) making a `git` commit.

```bash
usage: git save-work
```

A sequence of original `git` commands:
```bash
git add --interactive
git diff --cached --check
git commit
```

# `accept-work`
Accepts proposed work (remote work branch) on top of the fresh history of remote `master` (using
`rebase`) and publishes work to `origin/master`. Also, it removes the remote work branch in case of
Expand Down Expand Up @@ -82,6 +96,3 @@ Shows trailing whitespaces of uncommitted changes.

# `commands`
Displays all available commands.

# `save`
Saves the changes to the current branch as a commit.
1 change: 1 addition & 0 deletions libexec/git-elegant-check
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set -e

default() {
echo "This command is deprecated. It will be removed soon."
case "$1" in
"-a" | "--all")
boxtee git diff --check
Expand Down
2 changes: 1 addition & 1 deletion libexec/git-elegant-commands
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set -e

default() {
echo "start-work"
echo "save-work"
echo "accept-work"
echo "pull"
echo "push"
Expand All @@ -14,5 +15,4 @@ default() {
echo "clear-local"
echo "configure-repository"
echo "check"
echo "save"
}
2 changes: 1 addition & 1 deletion libexec/git-elegant-save → libexec/git-elegant-save-work
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ set -e

default(){
boxtee git add --interactive
git elegant check --staged
boxtee git diff --cached --check
boxtee git commit
}
4 changes: 2 additions & 2 deletions tests/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 3 ]
[ "${#lines[@]}" -eq 4 ]
}

@test "'check': trailing spaces in the staged changes" {
init-repo && add-st-change "the space "
check git-elegant check -s
[ "$status" -eq 2 ]
[ "${lines[4]}" = "+the space " ]
[ "${lines[5]}" = "+the space " ]

}
39 changes: 22 additions & 17 deletions tests/git-elegant-commands.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,29 @@ teardown() {
}

@test "'commands': print all available commands" {
check git-elegant commands
[ "${lines[0]}" = "start-work" ]
[ "${lines[1]}" = "accept-work" ]
[ "${lines[2]}" = "pull" ]
[ "${lines[3]}" = "push" ]
[ "${lines[4]}" = "push-after-rebase" ]
[ "${lines[5]}" = "rebase" ]
[ "${lines[6]}" = "init" ]
[ "${lines[7]}" = "acquire-repository" ]
[ "${lines[8]}" = "add" ]
[ "${lines[9]}" = "clear-local" ]
[ "${lines[10]}" = "configure-repository" ]
[ "${lines[11]}" = "check" ]
[ "${lines[12]}" = "save" ]
[ ${#lines[@]} -eq 13 ]
COMMANDS=(
"start-work"
"save-work"
"accept-work"
"pull"
"push"
"push-after-rebase"
"rebase"
"init"
"acquire-repository"
"add"
"clear-local"
"configure-repository"
"check"
)
check git-elegant commands
for command in {0..12}; do
[ "${lines[$command]}" = "${COMMANDS[$command]}" ]
done
[ ${#lines[@]} -eq 13 ]
}

@test "'commands': default exit code is 0" {
check git-elegant commands
[ "$status" -eq 0 ]
check git-elegant commands
[ "$status" -eq 0 ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ teardown() {

setup() {
fake-pass git "add --interactive"
fake-pass git "elegant check --staged"
fake-pass git "diff --cached --check"
fake-pass git commit
}

@test "'save': command is available" {
check git-elegant save
@test "'save-work': command is available" {
check git-elegant save-work
[ "$status" -eq 0 ]
}

0 comments on commit 9b50cf8

Please sign in to comment.