Skip to content

Commit

Permalink
Add deliver-work command
Browse files Browse the repository at this point in the history
The command aims to publish current local branch. Before, it will
bring latest changes from remote `master` and apply your commits on
top of them.
  • Loading branch information
extsoft committed Jul 25, 2019
1 parent 6204217 commit a0b3698
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
`git elegant <command>` where `<command>` is one of

- `start-work`
- `save-work`
- `deliver-work`
- `accept-work`
- `pull`
- `push`
Expand Down Expand Up @@ -44,6 +46,20 @@ git diff --cached --check
git commit
```

# `deliver-work`
Updates the current branch using the latest remote `master` and updates remote refs.

```bash
usage: git deliver-work
```

A sequence of original `git` commands:
```bash
git fetch
git rebase origin/master
git push --set-upstream --force origin {local branch name}:{local branch name}
```

# `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
1 change: 1 addition & 0 deletions libexec/git-elegant-commands
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -e
default() {
echo "start-work"
echo "save-work"
echo "deliver-work"
echo "accept-work"
echo "pull"
echo "push"
Expand Down
13 changes: 13 additions & 0 deletions libexec/git-elegant-deliver-work
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e

default() {
local BRANCH=$(__branches 'git branch | grep \*')
if [[ "$BRANCH" == "master" ]]; then
box "No pushes to 'master' branch. Please read more on ${__site}"
exit 81
fi
boxtee git fetch
boxtee git rebase ${RMASTER}
boxtee git push --set-upstream --force origin ${BRANCH}:${BRANCH}
}
1 change: 1 addition & 0 deletions tests/git-elegant-commands.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ teardown() {
COMMANDS=(
"start-work"
"save-work"
"deliver-work"
"accept-work"
"pull"
"push"
Expand Down
29 changes: 29 additions & 0 deletions tests/git-elegant-deliver-work.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bats

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

teardown() {
clean-fake
}

@test "'deliver-work': by default, a name of remote branch is equal to local branch" {
fake-pass git branch *feature1
fake-pass git "fetch"
fake-pass git "rebase origin/master"
fake-pass git "push --set-upstream --force origin feature1:feature1"
check git-elegant deliver-work
[ "$status" -eq 0 ]
[ "${lines[7]}" = "== git push --set-upstream --force origin feature1:feature1 ==" ]
}

@test "'deliver-work': raise error #81 if current local branch is master" {
fake-pass git branch *master
fake-pass git "fetch"
fake-pass git "rebase origin/master"
fake-pass git "push --set-upstream --force origin master:master"
check git-elegant deliver-work
[ "$status" -eq 81 ]
[ "${lines[1]}" = "== No pushes to 'master' branch. Please read more on https://elegant-git.bees-hive.org ==" ]
}

0 comments on commit a0b3698

Please sign in to comment.