Skip to content

Commit

Permalink
Allow delivering a subset of the changes by deliver-work
Browse files Browse the repository at this point in the history
Sometimes, we need to deliver only a subset of changes to a remote
server. And as `deliver-work` uses a rebase, we have to stash
uncommitted modification prior to rebase and un-stash after the push.

#168
  • Loading branch information
extsoft committed Sep 29, 2019
1 parent c004a3f commit 344fd7e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
4 changes: 4 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ it pushes HEAD to appropriate upstream branch. By default, the name of remote
branch is equal to the local one. Also, you can give a custom name of
the remote branch if needed.

If there are uncommitted changes, they will be stashed prior to the command
execution and un-stashed after its successful completion. This is useful if you
need to deliver only sub-set of the changes.

Approximate commands flow is
```bash
==>> git elegant deliver-work
Expand Down
26 changes: 17 additions & 9 deletions libexec/git-elegant-deliver-work
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ it pushes HEAD to appropriate upstream branch. By default, the name of remote
branch is equal to the local one. Also, you can give a custom name of
the remote branch if needed.
If there are uncommitted changes, they will be stashed prior to the command
execution and un-stashed after its successful completion. This is useful if you
need to deliver only sub-set of the changes.
Approximate commands flow is
\`\`\`bash
==>> git elegant deliver-work
Expand All @@ -30,17 +34,21 @@ git push --set-upstream --force origin task-123:task-123
MESSAGE
}

--deliver-work-logic() {
git-verbose fetch
git-verbose rebase ${RMASTER}
local remote_branch=${1}
if [[ -n "${2}" ]]; then
remote_branch=${2}
fi
git-verbose push --set-upstream --force origin ${1}:${remote_branch}
}

default() {
local BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$BRANCH" == "master" ]]; then
local branch=$(git rev-parse --abbrev-ref HEAD)
if [[ "${branch}" == "master" ]]; then
error-box "No pushes to 'master' branch. Please read more on ${__site}"
exit 42
fi
git-verbose fetch
git-verbose rebase ${RMASTER}
local REMOTE_BRANCH=${BRANCH}
if [ -n "${1}" ]; then
REMOTE_BRANCH=${1}
fi
git-verbose push --set-upstream --force origin ${BRANCH}:${REMOTE_BRANCH}
stash-pipe --deliver-work-logic ${branch} "${@}"
}
15 changes: 15 additions & 0 deletions tests/git-elegant-deliver-work.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
load addons-common
load addons-read
load addons-fake
load addons-git

setup() {
init-repo
}

teardown() {
clean-fake
clean-git
}

@test "'deliver-work': by default, a name of remote branch is equal to local branch" {
Expand Down Expand Up @@ -37,3 +43,12 @@ teardown() {
[ "$status" -eq 42 ]
[ "${lines[1]}" = "== No pushes to 'master' branch. Please read more on https://elegant-git.bees-hive.org ==" ]
}

@test "'deliver-work': use stash pipe if there are uncommitted changes" {
fake-pass git pull
gitrepo "echo stash >> ${FILE_TO_MODIFY}"
check git-elegant start-work test-feature
[[ "$status" -eq 0 ]]
[[ "${lines[@]}" =~ "git stash push" ]]
[[ "${lines[@]}" =~ "git stash pop" ]]
}

0 comments on commit 344fd7e

Please sign in to comment.