Skip to content

Commit 4c86238

Browse files
authored
feat(hotfix): add backmerge option to release branch (#71)
Add new option releaseBackMerge to git flow hotfix finish when there is an existing release on a remote repository we can now backmerge the hotfix onto the release branch as well as develop and master. closes #69 closes nvie/gitflow#177 closes petervanderdoes/gitflow-avh#161
2 parents 1d729c6 + 830156f commit 4c86238

File tree

2 files changed

+55
-17
lines changed

2 files changed

+55
-17
lines changed

CHANGELOG.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
#### 2.2.0-SNAPSHOT
4+
* feat: add option to hotfix finish to allow for backmerge to release branch. Thank You [Bankers88](https://github.com/Bankers88)
45
* fix: Prevent hotfixes being merged to develop with nobackmerge flag. Thank You [adamrodger](https://github.com/adamrodger)
56
* feat(feature): add release sub command. Thank You [codesurf42](https://github.com/codesurf42) for the initial pr
67
* feat(init): add sign flag to create initial signed commit
@@ -10,15 +11,13 @@
1011
* fix: wording for help text in git flow log pull request #15 from Shea690901/hotfix/git-flow-log_help-message
1112
* refactor(git-flow): add support for busybox-readlink request #12 from KAction/readlink-busybox
1213

13-
1414
#### 2.1.0
1515
* feat: add create command to release allowing for a single step release prodution
1616
* feat: add missing hook script filter-flow-release-finish-version
1717
* fix: multi-line tag message when using -m
1818
* docs: update readme with better description as to why this fork was created. Thank You [shaedrick](https://github.com/shaedrich)
1919
**NOTE:** The format for a multi-line tag message is now "$(printf 'line of text with \n escape codes placed as needed for proper formating of the message')"
2020

21-
2221
#### 2.0.1
2322
* fix incorrect version identification along with updating source repository in gitflow-installer. Corrections pointed out by [bobstuart](https://github.com/bobstuart)
2423

git-flow-hotfix

+54-15
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ k,[no]keep Keep branch after performing finish
383383
D,[no]force_delete Force delete hotfix branch after finish
384384
n,[no]notag Don't tag this hotfix
385385
b,[no]nobackmerge Don't back-merge master, or tag if applicable, in develop
386+
r,releaseBackmerge Back-merge to release branch if exists
386387
S,[no]squash Squash hotfix during merge
387388
T,tagname! Use given tag name
388389
"
@@ -401,25 +402,27 @@ T,tagname! Use given tag name
401402
DEFINE_boolean 'force_delete' false "force delete hotfix branch after finish" D
402403
DEFINE_boolean 'notag' false "don't tag this hotfix" n
403404
DEFINE_boolean 'nobackmerge' false "don't back-merge $MASTER_BRANCH, or tag if applicable, in $DEVELOP_BRANCH " b
405+
DEFINE_boolean 'releasebackmerge' false "back-merge to release branch if exists" r
404406
DEFINE_boolean 'squash' false "squash release during merge" S
405407
DEFINE_boolean 'squash-info' false "add branch info during squash"
406408
DEFINE_string 'tagname' "" "use the given tag name" T
407409

408410
# Override defaults with values from config
409-
gitflow_override_flag_boolean "hotfix.finish.fetch" "fetch"
410-
gitflow_override_flag_boolean "hotfix.finish.sign" "sign"
411-
gitflow_override_flag_boolean "hotfix.finish.push" "push"
412-
gitflow_override_flag_boolean "hotfix.finish.keep" "keep"
413-
gitflow_override_flag_boolean "hotfix.finish.keepremote" "keepremote"
414-
gitflow_override_flag_boolean "hotfix.finish.keeplocal" "keeplocal"
415-
gitflow_override_flag_boolean "hotfix.finish.force-delete" "force_delete"
416-
gitflow_override_flag_boolean "hotfix.finish.notag" "notag"
417-
gitflow_override_flag_boolean "hotfix.finish.nobackmerge" "nobackmerge"
418-
gitflow_override_flag_boolean "hotfix.finish.squash" "squash"
419-
gitflow_override_flag_boolean "hotfix.finish.squash-info" "squash_info"
420-
gitflow_override_flag_string "hotfix.finish.signingkey" "signingkey"
421-
gitflow_override_flag_string "hotfix.finish.message" "message"
422-
gitflow_override_flag_string "hotfix.finish.messagefile" "messagefile"
411+
gitflow_override_flag_boolean "hotfix.finish.fetch" "fetch"
412+
gitflow_override_flag_boolean "hotfix.finish.sign" "sign"
413+
gitflow_override_flag_boolean "hotfix.finish.push" "push"
414+
gitflow_override_flag_boolean "hotfix.finish.keep" "keep"
415+
gitflow_override_flag_boolean "hotfix.finish.keepremote" "keepremote"
416+
gitflow_override_flag_boolean "hotfix.finish.keeplocal" "keeplocal"
417+
gitflow_override_flag_boolean "hotfix.finish.force-delete" "force_delete"
418+
gitflow_override_flag_boolean "hotfix.finish.notag" "notag"
419+
gitflow_override_flag_boolean "hotfix.finish.nobackmerge" "nobackmerge"
420+
gitflow_override_flag_boolean "hotfix.finish.releasebackmerge" "releasebackmerge"
421+
gitflow_override_flag_boolean "hotfix.finish.squash" "squash"
422+
gitflow_override_flag_boolean "hotfix.finish.squash-info" "squash_info"
423+
gitflow_override_flag_string "hotfix.finish.signingkey" "signingkey"
424+
gitflow_override_flag_string "hotfix.finish.message" "message"
425+
gitflow_override_flag_string "hotfix.finish.messagefile" "messagefile"
423426

424427
# Parse arguments
425428
parse_args "$@"
@@ -564,19 +567,54 @@ T,tagname! Use given tag name
564567
else
565568
commit="$BASE_BRANCH"
566569
fi
567-
568570
# merge master to develop
569571
git_do checkout "$DEVELOP_BRANCH" || die "Could not check out branch '$DEVELOP_BRANCH'."
570572
git_do merge --no-ff "$commit" || die "There were merge conflicts." # TODO: What do we do now?
571573
fi
572574
fi
573575

576+
if flag releasebackmerge; then
577+
_releasePrefix=$(git config --get gitflow.prefix.release)
578+
release_branches=$(git_local_branches_prefixed "$_releasePrefix")
579+
release_branch=
580+
# Check if there is a release branch
581+
if [ -n "$release_branches" ]; then
582+
# Get the release branch name
583+
release_branch=$(echo ${release_branches} | head -n1)
584+
# Check if release branch exists on remote
585+
if git_remote_branch_exists "$ORIGIN/$release_branch"; then
586+
# Try to merge into release.
587+
# In case a previous attempt to finish this release branch has failed,
588+
# but the merge into release was successful, we skip it now
589+
if ! git_is_branch_merged_into "$MERGE_BRANCH" "$release_branch"; then
590+
git_do checkout "$release_branch" || die "Could not check out branch '$release_branch'."
591+
# Accounting for 'git describe', if a release is tagged
592+
# we use the tag commit instead of the branch.
593+
if noflag notag; then
594+
commit="$VERSION_PREFIX$TAGNAME"
595+
else
596+
commit="$BASE_BRANCH"
597+
fi
598+
else
599+
commit="$BRANCH"
600+
fi
601+
git_do merge --no-ff "$commit" || die "There were merge conflicts."
602+
# TODO: What do we do now?
603+
else
604+
echo "Remote release $release_branch not found"
605+
fi
606+
fi
607+
fi
608+
574609
run_post_hook "$VERSION_PREFIX$TAGNAME" "$ORIGIN" "$BRANCH"
575610

576611
if flag push; then
577612
if [ "$BASE_BRANCH" = "$MASTER_BRANCH" ]; then
578613
git_do push "$ORIGIN" "$DEVELOP_BRANCH" || die "Could not push branch '$DEVELOP_BRANCH' to remote '$ORIGIN'."
579614
fi
615+
if [ -n "$release_branch" ]; then
616+
git_do push "$ORIGIN" "$release_branch" || dir "Could not push branch '$release_branch' to remote '$ORIGIN'."
617+
fi
580618
git_do push "$ORIGIN" "$BASE_BRANCH" || die "Could not push branch '$BASE_BRANCH' to remote '$ORIGIN'."
581619
if noflag notag; then
582620
git_do push --tags "$ORIGIN" || die "Could not push tags to remote '$ORIGIN'."
@@ -623,6 +661,7 @@ T,tagname! Use given tag name
623661
fi
624662
if [ "$BASE_BRANCH" = "$MASTER_BRANCH" ]; then
625663
[ "$commit" = "$BASE_BRANCH" ] && echo "- Master branch '$BASE_BRANCH' has been back-merged into '$DEVELOP_BRANCH'"
664+
[ -n "$release_branch" ] && echo "- Hotfix tag '$VERSION_PREFIX$TAGNAME' has been back-merged into '$release_branch'"
626665
[ "$commit" = "$VERSION_PREFIX$TAGNAME" ] && echo "- Hotfix tag '$VERSION_PREFIX$TAGNAME' has been back-merged into '$DEVELOP_BRANCH'"
627666
[ "$commit" = "$BRANCH" ] && echo "- Hotfix branch '$BRANCH' has been merged into '$DEVELOP_BRANCH'"
628667
fi

0 commit comments

Comments
 (0)