Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read multi slash branch names when deliver-work #256

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions libexec/git-elegant
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ _error-if-empty() {
fi
}

branch-from-remote-reference() {
# usage: branch-from-remote-reference <full reference name>
echo ${1} | sed "s|^[a-zA-Z0-9_-]*/||g"
}

remove-file() {
[[ -f ${1} ]] && rm ${1}
}
Expand Down
3 changes: 2 additions & 1 deletion libexec/git-elegant-accept-work
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ MESSAGE
if are-there-remotes; then
git-verbose push ${REMOTE_NAME} ${MASTER}:${MASTER}
if [[ ${actual_remote} =~ ^origin/ ]]; then
git-verbose push ${REMOTE_NAME} --delete $(branch-from-remote-reference ${actual_remote})
source ${BINS}/plugins/transformation
git-verbose push ${REMOTE_NAME} --delete $(branch-from-remote-branch ${actual_remote})
fi
fi
}
Expand Down
13 changes: 7 additions & 6 deletions libexec/git-elegant-deliver-work
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,26 @@ MESSAGE

--deliver-work-logic() {
source ${BINS}/plugins/state
source ${BINS}/plugins/transformation
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:short)" ${1})
local remote_branch=${upstream/*\//}
local remote=${upstream/\/*/}
local branch=$(branch-from-remote-branch ${upstream})
local remote=$(remote-from-remote-branch ${upstream})
if [[ -n "${2}" ]]; then
remote_branch=${2}
branch=${2}
fi
if [[ -z "${remote_branch}" ]]; then
remote_branch=${1}
if [[ -z "${branch}" ]]; then
branch=${1}
fi
if [[ -z "${remote}" ]]; then
remote=${REMOTE_NAME}
fi
git-verbose-op --open-urls-if-possible push --set-upstream --force ${remote} ${1}:${remote_branch}
git-verbose-op --open-urls-if-possible push --set-upstream --force ${remote} ${1}:${branch}
}

default() {
Expand Down
3 changes: 2 additions & 1 deletion libexec/git-elegant-obtain-work
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ default() {
local REMOTE=${REMOTE_BRANCHES[0]}
local LOCAL=${2}
if [[ -z ${LOCAL} ]]; then
LOCAL=$(branch-from-remote-reference ${REMOTE})
source ${BINS}/plugins/transformation
LOCAL=$(branch-from-remote-branch ${REMOTE})
fi
git-verbose checkout -B ${LOCAL} ${REMOTE}
else
Expand Down
15 changes: 15 additions & 0 deletions libexec/plugins/transformation
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
# The plugin holds functions that convert one object into another.
# The most part of functions manipulates with strings.

branch-from-remote-branch() {
# usage : echo $(branch-from-remote-branch origin/feature/a)
# result: feature/a
echo ${1#*/}
}

remote-from-remote-branch() {
# usage : echo $(remote-from-remote-branch origin/feature/a)
# result: origin
echo ${1%%/*}
}
10 changes: 5 additions & 5 deletions tests/git-elegant-deliver-work.bats
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ teardown() {
}

@test "'deliver-work': use existing upstream branch if it is available" {
repo "git checkout -b some/remote"
repo "git checkout -b feature1"
repo "git branch --set-upstream-to some/remote"
fake-pass "git push --set-upstream --force some feature1:remote"
repo "git checkout -b some-remote/feature/123"
repo "git checkout -b 123"
repo "git branch --set-upstream-to some-remote/feature/123"
fake-pass "git push --set-upstream --force some-remote 123:feature/123"
check git-elegant deliver-work
[[ ${status} -eq 0 ]]
[[ ${lines[@]} =~ "git push --set-upstream --force some feature1:remote" ]]
[[ ${lines[@]} =~ "git push --set-upstream --force some-remote 123:feature/123" ]]
}

@test "'deliver-work': open URls if they are present in the push output" {
Expand Down