From 7ee46b796b3ad5ecf446f61fe70d82e22a226502 Mon Sep 17 00:00:00 2001 From: alexbeatnik Date: Sun, 29 Sep 2019 12:53:45 +0300 Subject: [PATCH] Don't remove fork remote branch when `accept-work` Add check of remote branch to git-elegant accept-work command if remote branch is not origin/... script do not delete it Also add test for this functionality #171 --- libexec/git-elegant-accept-work | 5 ++++- tests/git-elegant-accept-work.bats | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/libexec/git-elegant-accept-work b/libexec/git-elegant-accept-work index 0b5484e..1232f8f 100644 --- a/libexec/git-elegant-accept-work +++ b/libexec/git-elegant-accept-work @@ -53,5 +53,8 @@ default() { git-verbose merge --ff-only ${WORK_BRANCH} git-verbose push ${REMOTE_NAME} ${MASTER}:${MASTER} git-verbose branch --delete --force ${WORK_BRANCH} - git-verbose push ${REMOTE_NAME} --delete $(branch-from-remote-reference ${ACTUAL_REMOTE}) + if [[ ${REMOTE_NAME} == *"origin"* ]]; then + git-verbose push ${REMOTE_NAME} --delete $(branch-from-remote-reference ${ACTUAL_REMOTE}) + fi + } diff --git a/tests/git-elegant-accept-work.bats b/tests/git-elegant-accept-work.bats index 5692041..30ea238 100644 --- a/tests/git-elegant-accept-work.bats +++ b/tests/git-elegant-accept-work.bats @@ -7,7 +7,7 @@ teardown() { clean-fake } -@test "'accept-work': a work is accepted successfully for given remote branch" { +@test "'accept-work': a work is accepted successfully for given origin remote branch" { fake-pass git "elegant obtain-work some __eg" fake-pass git "status" fake-pass git "rebase origin/master" @@ -22,6 +22,19 @@ teardown() { [[ "$status" -eq 0 ]] } +@test "'accept-work': a work is accepted successfully for given no origin remote branch" { + fake-pass git "elegant obtain-work some __eg" + fake-pass git "status" + fake-pass git "rebase feature/master" + fake-pass git "checkout master" + fake-pass git "merge --ff-only __eg" + fake-pass git "push feature master:master" + fake-pass git "branch --delete --force __eg" + + check git-elegant accept-work some + [[ "$status" -eq 0 ]] +} + @test "'accept-work': exit code is 45 when remote branch name isn't set" { check git-elegant accept-work [[ "$status" -eq 45 ]]