Skip to content

Commit

Permalink
Support active rebase process during deliver-work execution
Browse files Browse the repository at this point in the history
It happens that there are conflicts during the rebase of the latest
HEAD into the current work branch. And once they are solved, the
`deliver-work` execution one more time allows continuing current
rebase and delivering work.
  • Loading branch information
extsoft committed Nov 30, 2019
1 parent 4f97e02 commit ca0f62f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
5 changes: 3 additions & 2 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ git elegant acquire-repository
usage: git elegant deliver-work [branch-name]
```

Updates the current branch by rebasing the default upstream branch. Then,
it pushes HEAD to the appropriate upstream branch.
Updates the current branch by rebasing the default upstream branch. If there is
a rebase in progress, the command will continue it instead of initiation a new
one. Then, it pushes HEAD to the appropriate upstream branch.

By default, the name of remote branch is equal to the local one. If a local
branch has an upstream branch configured, it will be used as a remote branch.
Expand Down
14 changes: 10 additions & 4 deletions libexec/git-elegant-deliver-work
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ MESSAGE

command-description() {
cat<<MESSAGE
Updates the current branch by rebasing the default upstream branch. Then,
it pushes HEAD to the appropriate upstream branch.
Updates the current branch by rebasing the default upstream branch. If there is
a rebase in progress, the command will continue it instead of initiation a new
one. Then, it pushes HEAD to the appropriate upstream branch.
By default, the name of remote branch is equal to the local one. If a local
branch has an upstream branch configured, it will be used as a remote branch.
Expand Down Expand Up @@ -50,8 +51,13 @@ MESSAGE
}

--deliver-work-logic() {
git-verbose fetch
git-verbose rebase ${RMASTER}
source ${BINS}/plugins/rebase
if is-there-active-rebase; then
git-verbose rebase --continue
else
git-verbose fetch
git-verbose rebase ${RMASTER}
fi
local upstream=$(git branch --list --format "%(upstream:lstrip=2)" ${1})
local remote_branch=${upstream/*\//}
local remote=${upstream/\/*/}
Expand Down
3 changes: 2 additions & 1 deletion libexec/git-elegant-polish-work
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ default() {
error-box "'master' branch history can't be rewritten. Please read more on ${__site}"
exit 42
fi
if test -d "$(git rev-parse --git-path rebase-merge)" || test -d "$(git rev-parse --git-path rebase-apply)"; then
source ${BINS}/plugins/rebase
if is-there-active-rebase; then
git-verbose rebase --continue
else
local commits=($(git rev-list ${MASTER}..@))
Expand Down
6 changes: 6 additions & 0 deletions libexec/plugins/rebase
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
# The plugin that wraps some useful operations around `git rebase`.

is-there-active-rebase(){
test -d "$(git rev-parse --git-path rebase-merge)" || test -d "$(git rev-parse --git-path rebase-apply)"
}
9 changes: 9 additions & 0 deletions tests/git-elegant-deliver-work.bats
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,12 @@ teardown() {
check git-elegant deliver-work
[[ "${status}" -eq 0 ]]
}

@test "'deliver-work': current rebase is continued when there is an active rebase process" {
repo "git checkout -b feature1"
fake-pass "git push --set-upstream --force origin feature1:feature1"
fake-pass "git rev-parse --git-path rebase-merge" ".git"
check git-elegant deliver-work
[[ ${status} -ne 0 ]]
[[ ${lines[@]} =~ "No rebase in progress?" ]]
}

0 comments on commit ca0f62f

Please sign in to comment.