Skip to content

Commit

Permalink
Merge pull request #11 from Djuuu/allow-mr-open-on-remote-branches
Browse files Browse the repository at this point in the history
Allow `mr status` & `mr open` on non-checked out branches
  • Loading branch information
Djuuu authored May 6, 2023
2 parents 152c79e + 4a30732 commit 6071ef3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ Prepares a merge request description, with link to Jira ticket and current branc
<b>git mr</b> <i>[OPTIONS]</i> <b>(ip|cr|qa|ok)</b> <i>[BRANCH]</i>
<b>git mr</b> <i>[OPTIONS]</i> <b>undraft</b> <i>[BRANCH]</i>

<b>git mr</b> <b>hook</b>
<b>git mr</b> <b>base</b> <i>[BRANCH]</i>
<b>git mr</b> <b>code</b> <i>[BRANCH]</i>

<b>git mr</b> <b>base</b>
<b>git mr</b> <b>code</b>
<b>git mr</b> <b>hook</b>
</pre>

### Arguments
Expand Down
24 changes: 14 additions & 10 deletions git-mr
Original file line number Diff line number Diff line change
Expand Up @@ -1941,19 +1941,20 @@ EOF
mr_open() {
local source_branch=${1:-$(git_current_branch)}
local target_branch=${2:-${GIT_MR_TARGET:-$(git_base_branch "$source_branch")}}
git_check_branches "$source_branch" "$target_branch"

local issue_code=${GIT_MR_CODE:-$(guess_issue_code "$source_branch")}
[[ -n $issue_code ]] || git_mr_unguessable_issue_code=1

local description; description=$(mr_description "$source_branch" "$target_branch" "$issue_code")

cat <<EOF
local description;
if [[ -n $target_branch ]]; then
description=$(mr_description "$source_branch" "$target_branch" "$issue_code")
cat <<EOF
--------------------------------------------------------------------------------
$description
EOF
fi

local mr_summary; mr_summary=$(gitlab_merge_request_summary "$source_branch")
if [[ -n $mr_summary ]]; then
Expand All @@ -1962,6 +1963,8 @@ EOF
# Print merge request status summary
mr_status_block "$mr_summary"
else
git_check_branches "$source_branch" "$target_branch"

echo "--------------------------------------------------------------------------------"
echo

Expand All @@ -1983,12 +1986,13 @@ mr_status() {
gitlab_check_env

local source_branch=${1:-$(git_current_branch)}
git_check_branches "$source_branch" "-"

# Search existing merge request
local mr_summary; mr_summary=$(gitlab_merge_request_summary "$source_branch")
if [[ -z $mr_summary ]]; then
echo_error "Merge request not found"

git_check_branches "$source_branch" "-"
mr_print "$source_branch"
return "$ERR_GITLAB"
fi
Expand Down Expand Up @@ -2514,10 +2518,10 @@ ${b}SYNOPSIS${r}
${u}git${r} ${u}mr${r} [OPTION...] (ip|cr|qa|ok) [BRANCH]
${u}git${r} ${u}mr${r} [OPTION...] undraft [BRANCH]
${u}git${r} ${u}mr${r} hook
${u}git${r} ${u}mr${r} base [BRANCH]
${u}git${r} ${u}mr${r} code [BRANCH]
${u}git${r} ${u}mr${r} base
${u}git${r} ${u}mr${r} code
${u}git${r} ${u}mr${r} hook
${b}ARGUMENTS${r}
BRANCH
Expand Down Expand Up @@ -2774,8 +2778,8 @@ case $1 in
hook) mr_hook ;;

# Plumbing
base) git_base_branch ;;
code) guess_issue_code ;;
base) git_base_branch "$2" ;;
code) guess_issue_code "$2" ;;

*) mr_print "$@" ;;

Expand Down
6 changes: 5 additions & 1 deletion test/git-mr.bats
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ full_sha() {
git switch main
run git-mr base
assert_failure "$ERR_GIT"

# with argument
run git-mr base feature/AB-123-test-feature
assert_output "feature/base"
}

@test "Determines remote name" {
Expand Down Expand Up @@ -814,7 +818,7 @@ full_sha() {
run git-mr code
assert_output "Unable to guess issue code"

run guess_issue_code feature/AB-123-CD-456-test-feature
run git-mr code feature/AB-123-CD-456-test-feature
assert_output "CD-456" # debatable
}

Expand Down

0 comments on commit 6071ef3

Please sign in to comment.