@@ -366,7 +366,7 @@ showcommands! Show git commands while executing them
366
366
367
367
cmd_finish () {
368
368
OPTIONS_SPEC=" \
369
- git flow hotfix finish [-h] [-F] [-s] [-u] [-m | -f ] [-p] [-k] [-n] [-b] [-S] <version>
369
+ git flow hotfix finish [-h] [-F] [-s] [-u] [-m | -f ] [-p] [-k] [-n] [-b | -c ] [-S] <version>
370
370
371
371
Finish hotfix branch <version>
372
372
--
@@ -387,6 +387,7 @@ b,[no]nobackmerge Don't back-merge master, or tag if applicable, in develop
387
387
r,releaseBackmerge Back-merge to release branch if exists
388
388
S,[no]squash Squash hotfix during merge
389
389
T,tagname! Use given tag name
390
+ c,cherrypick Cherry Pick to $DEVELOP_BRANCH instead of merge
390
391
"
391
392
local opts commit keepmsg remotebranchdeleted localbranchdeleted
392
393
@@ -407,6 +408,7 @@ T,tagname! Use given tag name
407
408
DEFINE_boolean ' squash' false " squash release during merge" S
408
409
DEFINE_boolean ' squash-info' false " add branch info during squash"
409
410
DEFINE_string ' tagname' " " " use the given tag name" T
411
+ DEFINE_boolean ' cherrypick' false " Cherry Pick to $DEVELOP_BRANCH instead of merge" c
410
412
411
413
# Override defaults with values from config
412
414
gitflow_override_flag_boolean " hotfix.finish.fetch" " fetch"
@@ -424,6 +426,7 @@ T,tagname! Use given tag name
424
426
gitflow_override_flag_string " hotfix.finish.signingkey" " signingkey"
425
427
gitflow_override_flag_string " hotfix.finish.message" " message"
426
428
gitflow_override_flag_string " hotfix.finish.messagefile" " messagefile"
429
+ gitflow_override_flag_boolean " hotfix.finish.cherrypick" " cherrypick"
427
430
428
431
# Parse arguments
429
432
parse_args " $@ "
@@ -453,6 +456,15 @@ T,tagname! Use given tag name
453
456
FLAGS_keep=$FLAGS_TRUE
454
457
fi
455
458
459
+ # Check that not both no merge flags were given
460
+ if flag cherrypick && flag nobackmerge; then
461
+ die " You can't use 'cherrypick' and 'nobackmerge' together."
462
+ fi
463
+
464
+ if flag cherrypick && flag releasebackmerge; then
465
+ die " You can't use 'cherrypick' and 'releasebackmerge' together."
466
+ fi
467
+
456
468
# Sanity checks
457
469
require_branch " $BRANCH "
458
470
require_clean_working_tree
@@ -521,6 +533,42 @@ T,tagname! Use given tag name
521
533
522
534
run_pre_hook " $VERSION_PREFIX$TAGNAME " " $ORIGIN " " $BRANCH "
523
535
536
+ if flag cherrypick; then
537
+ printf ' this is the cherrypick\n'
538
+ read
539
+ git_do checkout " $DEVELOP_BRANCH " || die " Could not check out branch '$DEVELOP_BRANCH '."
540
+
541
+ local old_IFS=$IFS # save the field separator
542
+ IFS=$' \n ' # new field separator, the end of line
543
+ for git_line in $( git log --format=" %H %s" --reverse $MASTER_BRANCH ..$BRANCH | grep -vE " ^[a-z0-9]* Merge branch '[^'].*?'$" ) ; do
544
+ local commit_hash=$( echo $git_line | cut -d" " -f1)
545
+ if [[ $( git log $DEVELOP_BRANCH --grep " $commit_hash " | wc -l) -eq 0 ]]; then
546
+ echo " \n${LIGHTGREEN} Cherry picking: $git_line ${NOCOLOR} "
547
+ git_do cherry-pick -x -s $commit_hash
548
+ if [[ $? -ne 0 ]]; then
549
+ echo "
550
+ ===============================================================
551
+ = Cherry pick has conflicts, steps to continue:
552
+ = 1. Fix the conflicts
553
+ = 2. Stage the fixed file: '${BLUE} git add <file names>${NOCOLOR} '
554
+ = 3. Continue the cherry pick: '${BLUE} git cherry-pick --continue${NOCOLOR} '
555
+ = *** If fixing the conflict results in an empty commit,
556
+ = you will need to run this command: '${BLUE} git commit --allow-empty${NOCOLOR} '
557
+ = 4. Switch back to the hotfix branch: '${BLUE} git checkout $BRANCH ${NOCOLOR} '
558
+ = 5. Rerun the finish command: '${BLUE} git flow hotfix finish${NOCOLOR} '
559
+ = OR run '${BLUE} git cherry-pick --abort${NOCOLOR} ' to abort the cherry pick
560
+ ===============================================================\n"
561
+ die " Cherry pick failed for commit: $commit_hash "
562
+ fi
563
+ else
564
+ echo " \n${LIGHTGREEN} Commit has already been Cherry Picked: $git_line ${NOCOLOR} "
565
+ fi
566
+ done
567
+ IFS=$old_IFS # restore default field separator
568
+
569
+ git_do checkout $BRANCH || die " Could not check out branch '$BRANCH '."
570
+ fi
571
+
524
572
# Try to merge into BASE.
525
573
# In case a previous attempt to finish this release branch has failed,
526
574
# but the merge into BASE was successful, we skip it now
@@ -556,7 +604,7 @@ T,tagname! Use given tag name
556
604
fi
557
605
fi
558
606
559
- if [ " $BASE_BRANCH " = " $MASTER_BRANCH " ] && noflag nobackmerge; then
607
+ if [ " $BASE_BRANCH " = " $MASTER_BRANCH " ] && noflag nobackmerge && noflag cherrypick ; then
560
608
# Try to merge into develop unless the user specified the nobackmerge option.
561
609
# In case a previous attempt to finish this release branch has failed,
562
610
# but the merge into develop was successful, we skip it now
@@ -660,12 +708,15 @@ T,tagname! Use given tag name
660
708
if noflag notag; then
661
709
echo " - The hotfix was tagged '$VERSION_PREFIX$TAGNAME '"
662
710
fi
663
- if [ " $BASE_BRANCH " = " $MASTER_BRANCH " ]; then
711
+ if flag cherrypick; then
712
+ echo " - All commits from the hotfix branch have been cherry picked into '$DEVELOP_BRANCH '"
713
+ elif [ " $BASE_BRANCH " = " $MASTER_BRANCH " ]; then
664
714
[ " $commit " = " $BASE_BRANCH " ] && echo " - Master branch '$BASE_BRANCH ' has been back-merged into '$DEVELOP_BRANCH '"
665
715
[ -n " $release_branch " ] && echo " - Hotfix tag '$VERSION_PREFIX$TAGNAME ' has been back-merged into '$release_branch '"
666
- [ " $commit " = " $VERSION_PREFIX$TAGNAME " ] && echo " - Hotfix tag '$VERSION_PREFIX$TAGNAME ' has been back-merged into '$DEVELOP_BRANCH '"
716
+ [ " $commit " = " $VERSION_PREFIX$VERSION " ] && echo " - Hotfix tag '$VERSION_PREFIX$VERSION ' has been back-merged into '$DEVELOP_BRANCH '"
667
717
[ " $commit " = " $BRANCH " ] && echo " - Hotfix branch '$BRANCH ' has been merged into '$DEVELOP_BRANCH '"
668
718
fi
719
+
669
720
if noflag keep; then
670
721
if [ $localbranchdeleted -eq $FLAGS_TRUE ]; then
671
722
keepmsg=" has been locally deleted"
0 commit comments