From e970e444f10122ceffb27e080af661918c9ffcc8 Mon Sep 17 00:00:00 2001 From: bertubezz Date: Sat, 15 Sep 2018 19:51:55 +0200 Subject: [PATCH 1/2] Adding fetch argument to the rebase command. --- git-flow-bugfix | 10 +++++++++- git-flow-feature | 10 +++++++++- git-flow-hotfix | 10 +++++++++- git-flow-release | 9 ++++++++- git-flow-support | 10 +++++++++- 5 files changed, 44 insertions(+), 5 deletions(-) diff --git a/git-flow-bugfix b/git-flow-bugfix index 720e86dc..a89d8294 100644 --- a/git-flow-bugfix +++ b/git-flow-bugfix @@ -627,7 +627,7 @@ cmd_co() { cmd_rebase() { OPTIONS_SPEC="\ -git flow bugfix rebase [-h] [-i] [-p] [] +git flow bugfix rebase [-h] [-i] [-p] [-F] [] Rebase on -- @@ -635,16 +635,19 @@ h,help! Show this help showcommands! Show git commands while executing them i,[no]interactive Do an interactive rebase p,[no]preserve-merges Preserve merges +F,[no]fetch Fetch from origin before performing local operation " local opts # Define flags DEFINE_boolean 'interactive' false 'do an interactive rebase' i DEFINE_boolean 'preserve-merges' false 'try to recreate merges' p + DEFINE_boolean 'fetch' false 'fetch from origin before performing local operation' F # Override defaults with values from config gitflow_override_flag_boolean "bugfix.rebase.interactive" "interactive" gitflow_override_flag_boolean "bugfix.rebase.preserve-merges" "preserve_merges" + gitflow_override_flag_boolean "bugfix.rebase.fetch" "fetch" # Parse arguments parse_args "$@" @@ -666,6 +669,11 @@ p,[no]preserve-merges Preserve merges git_local_branch_exists "$BASE_BRANCH" || die "The base '$BASE_BRANCH' doesn't exists locally or is not a branch. Can't rebase the bugfix branch '$BRANCH'." + # Update local branches with remote branches + if flag fetch; then + git_fetch_branch "$ORIGIN" "$BASE_BRANCH" + fi + git_do checkout -q "$BRANCH" || die "Could not check out branch '$BRANCH'." if flag interactive; then opts="$opts -i" diff --git a/git-flow-feature b/git-flow-feature index 275f54bd..c71ded4b 100644 --- a/git-flow-feature +++ b/git-flow-feature @@ -627,7 +627,7 @@ cmd_co() { cmd_rebase() { OPTIONS_SPEC="\ -git flow feature rebase [-h] [-i] [-p] [] +git flow feature rebase [-h] [-i] [-p] [-F] [] Rebase on -- @@ -635,16 +635,19 @@ h,help! Show this help showcommands! Show git commands while executing them i,[no]interactive Do an interactive rebase p,[no]preserve-merges Preserve merges +F,[no]fetch Fetch from origin before performing local operation " local opts # Define flags DEFINE_boolean 'interactive' false 'do an interactive rebase' i DEFINE_boolean 'preserve-merges' false 'try to recreate merges' p + DEFINE_boolean 'fetch' false 'fetch from origin before performing local operation' F # Override defaults with values from config gitflow_override_flag_boolean "feature.rebase.interactive" "interactive" gitflow_override_flag_boolean "feature.rebase.preserve-merges" "preserve_merges" + gitflow_override_flag_boolean "feature.rebase.fetch" "fetch" # Parse arguments parse_args "$@" @@ -667,6 +670,11 @@ p,[no]preserve-merges Preserve merges git_local_branch_exists "$BASE_BRANCH" || die "The base '$BASE_BRANCH' doesn't exists locally or is not a branch. Can't rebase the feature branch '$BRANCH'." + # Update local branches with remote branches + if flag fetch; then + git_fetch_branch "$ORIGIN" "$BASE_BRANCH" + fi + git_do checkout -q "$BRANCH" || die "Could not check out branch '$BRANCH'." if flag interactive; then opts="$opts -i" diff --git a/git-flow-hotfix b/git-flow-hotfix index f97ed44a..58b267b2 100644 --- a/git-flow-hotfix +++ b/git-flow-hotfix @@ -281,7 +281,7 @@ showcommands! Show git commands while executing them cmd_rebase() { OPTIONS_SPEC="\ -git flow hotfix rebase [-h] [-i] [-p] [] +git flow hotfix rebase [-h] [-i] [-p] [-F] [] Rebase on -- @@ -289,16 +289,19 @@ h,help! Show this help showcommands! Show git commands while executing them i,[no]interactive Do an interactive rebase p,[no]preserve-merges Preserve merges +F,[no]fetch Fetch from origin before performing local operation " local opts # Define flags DEFINE_boolean 'interactive' false 'do an interactive rebase' i DEFINE_boolean 'preserve-merges' false 'try to recreate merges' p + DEFINE_boolean 'fetch' false 'fetch from origin before performing local operation' F # Override defaults with values from config gitflow_override_flag_boolean "hotfix.rebase.interactive" "interactive" gitflow_override_flag_boolean "hotfix.rebase.preserve-merges" "preserve_merges" + gitflow_override_flag_boolean "hotfix.rebase.fetch" "fetch" # Parse arguments parse_args "$@" @@ -319,6 +322,11 @@ p,[no]preserve-merges Preserve merges git_local_branch_exists "$BASE_BRANCH" || die "The base '$BASE_BRANCH' doesn't exists locally or is not a branch. Can't rebase the hotfixe branch '$BRANCH'." + # Update local branches with remote branches + if flag fetch; then + git_fetch_branch "$ORIGIN" "$BASE_BRANCH" + fi + git_do checkout -q "$BRANCH" || die "Could not check out branch '$BRANCH'." if flag interactive; then opts="$opts -i" diff --git a/git-flow-release b/git-flow-release index e9c542da..661ef570 100644 --- a/git-flow-release +++ b/git-flow-release @@ -976,7 +976,7 @@ showcommands! Show git commands while executing them cmd_rebase() { OPTIONS_SPEC="\ -git flow release rebase [-h] [-i] [-p] [] +git flow release rebase [-h] [-i] [-p] [-F] [] Rebase on -- @@ -990,10 +990,12 @@ p,[no]preserve-merges Preserve merges # Define flags DEFINE_boolean 'interactive' false 'do an interactive rebase' i DEFINE_boolean 'preserve-merges' false 'try to recreate merges' p + DEFINE_boolean 'fetch' false 'fetch from origin before performing local operation' F # Override defaults with values from config gitflow_override_flag_boolean "release.rebase.interactive" "interactive" gitflow_override_flag_boolean "release.rebase.preserve-merges" "preserve_merges" + gitflow_override_flag_boolean "release.rebase.fetch" "fetch" # Parse arguments parse_args "$@" @@ -1014,6 +1016,11 @@ p,[no]preserve-merges Preserve merges git_local_branch_exists "$BASE_BRANCH" || die "The base '$BASE_BRANCH' doesn't exists locally or is not a branch. Can't rebase the release branch '$BRANCH'." + # Update local branches with remote branches + if flag fetch; then + git_fetch_branch "$ORIGIN" "$BASE_BRANCH" + fi + git_do checkout -q "$BRANCH" || die "Could not check out branch '$BRANCH'." if flag interactive; then opts="$opts -i" diff --git a/git-flow-support b/git-flow-support index 7957c196..4f3ccdce 100644 --- a/git-flow-support +++ b/git-flow-support @@ -202,7 +202,7 @@ F,[no]fetch Fetch from origin before performing finish cmd_rebase() { OPTIONS_SPEC="\ -git flow support rebase [-h] [-i] [-p] [] +git flow support rebase [-h] [-i] [-p] [-F] [] Rebase on -- @@ -210,16 +210,19 @@ h,help! Show this help showcommands! Show git commands while executing them i,[no]interactive Do an interactive rebase p,[no]preserve-merges Preserve merges +F,[no]fetch Fetch from origin before performing local operation " local opts # Define flags DEFINE_boolean 'interactive' false 'do an interactive rebase' i DEFINE_boolean 'preserve-merges' false 'try to recreate merges' p + DEFINE_boolean 'fetch' false 'fetch from origin before performing local operation' F # Override defaults with values from config gitflow_override_flag_boolean "support.rebase.interactive" "interactive" gitflow_override_flag_boolean "support.rebase.preserve-merges" "preserve_merges" + gitflow_override_flag_boolean "support.rebase.fetch" "fetch" # Parse arguments parse_args "$@" @@ -240,6 +243,11 @@ p,[no]preserve-merges Preserve merges git_local_branch_exists "$BASE_BRANCH" || die "The base '$BASE_BRANCH' doesn't exists locally or is not a branch. Can't rebase the support branch '$BRANCH'." + # Update local branches with remote branches + if flag fetch; then + git_fetch_branch "$ORIGIN" "$BASE_BRANCH" + fi + git_do checkout -q "$BRANCH" || die "Could not check out branch '$BRANCH'." if flag interactive; then opts="$opts -i" From 7b94aaddb05b2a3179441e26985029dd1754afc0 Mon Sep 17 00:00:00 2001 From: Albert Bezzina Date: Tue, 18 Sep 2018 08:09:11 +0200 Subject: [PATCH 2/2] FIX: when rebase is with fetch, rebase from origin. --- git-flow-bugfix | 14 ++++++++------ git-flow-feature | 14 ++++++++------ git-flow-hotfix | 14 ++++++++------ git-flow-release | 14 ++++++++------ git-flow-support | 14 ++++++++------ 5 files changed, 40 insertions(+), 30 deletions(-) diff --git a/git-flow-bugfix b/git-flow-bugfix index a89d8294..e05dd273 100644 --- a/git-flow-bugfix +++ b/git-flow-bugfix @@ -669,11 +669,6 @@ F,[no]fetch Fetch from origin before performing local operation git_local_branch_exists "$BASE_BRANCH" || die "The base '$BASE_BRANCH' doesn't exists locally or is not a branch. Can't rebase the bugfix branch '$BRANCH'." - # Update local branches with remote branches - if flag fetch; then - git_fetch_branch "$ORIGIN" "$BASE_BRANCH" - fi - git_do checkout -q "$BRANCH" || die "Could not check out branch '$BRANCH'." if flag interactive; then opts="$opts -i" @@ -681,7 +676,14 @@ F,[no]fetch Fetch from origin before performing local operation if flag preserve_merges; then opts="$opts -p" fi - git_do rebase $opts "$BASE_BRANCH" + + if flag fetch; then + # Update local branches with remote branches + git_fetch_branch "$ORIGIN" "$BASE_BRANCH" + git_do rebase $opts "$ORIGIN/$BASE_BRANCH" + else + git_do rebase $opts "$BASE_BRANCH" + fi } avoid_accidental_cross_branch_action() { diff --git a/git-flow-feature b/git-flow-feature index c71ded4b..3f56aa42 100644 --- a/git-flow-feature +++ b/git-flow-feature @@ -670,11 +670,6 @@ F,[no]fetch Fetch from origin before performing local operation git_local_branch_exists "$BASE_BRANCH" || die "The base '$BASE_BRANCH' doesn't exists locally or is not a branch. Can't rebase the feature branch '$BRANCH'." - # Update local branches with remote branches - if flag fetch; then - git_fetch_branch "$ORIGIN" "$BASE_BRANCH" - fi - git_do checkout -q "$BRANCH" || die "Could not check out branch '$BRANCH'." if flag interactive; then opts="$opts -i" @@ -682,7 +677,14 @@ F,[no]fetch Fetch from origin before performing local operation if flag preserve_merges; then opts="$opts -p" fi - git_do rebase $opts "$BASE_BRANCH" + + if flag fetch; then + # Update local branches with remote branches + git_fetch_branch "$ORIGIN" "$BASE_BRANCH" + git_do rebase $opts "$ORIGIN/$BASE_BRANCH" + else + git_do rebase $opts "$BASE_BRANCH" + fi } avoid_accidental_cross_branch_action() { diff --git a/git-flow-hotfix b/git-flow-hotfix index 58b267b2..0193599b 100644 --- a/git-flow-hotfix +++ b/git-flow-hotfix @@ -322,11 +322,6 @@ F,[no]fetch Fetch from origin before performing local operation git_local_branch_exists "$BASE_BRANCH" || die "The base '$BASE_BRANCH' doesn't exists locally or is not a branch. Can't rebase the hotfixe branch '$BRANCH'." - # Update local branches with remote branches - if flag fetch; then - git_fetch_branch "$ORIGIN" "$BASE_BRANCH" - fi - git_do checkout -q "$BRANCH" || die "Could not check out branch '$BRANCH'." if flag interactive; then opts="$opts -i" @@ -334,7 +329,14 @@ F,[no]fetch Fetch from origin before performing local operation if flag preserve_merges; then opts="$opts -p" fi - git_do rebase $opts "$BASE_BRANCH" + + if flag fetch; then + # Update local branches with remote branches + git_fetch_branch "$ORIGIN" "$BASE_BRANCH" + git_do rebase $opts "$ORIGIN/$BASE_BRANCH" + else + git_do rebase $opts "$BASE_BRANCH" + fi } cmd_track() { diff --git a/git-flow-release b/git-flow-release index 661ef570..e000d109 100644 --- a/git-flow-release +++ b/git-flow-release @@ -1016,11 +1016,6 @@ p,[no]preserve-merges Preserve merges git_local_branch_exists "$BASE_BRANCH" || die "The base '$BASE_BRANCH' doesn't exists locally or is not a branch. Can't rebase the release branch '$BRANCH'." - # Update local branches with remote branches - if flag fetch; then - git_fetch_branch "$ORIGIN" "$BASE_BRANCH" - fi - git_do checkout -q "$BRANCH" || die "Could not check out branch '$BRANCH'." if flag interactive; then opts="$opts -i" @@ -1028,7 +1023,14 @@ p,[no]preserve-merges Preserve merges if flag preserve_merges; then opts="$opts -p" fi - git_do rebase $opts "$BASE_BRANCH" + + if flag fetch; then + # Update local branches with remote branches + git_fetch_branch "$ORIGIN" "$BASE_BRANCH" + git_do rebase $opts "$ORIGIN/$BASE_BRANCH" + else + git_do rebase $opts "$BASE_BRANCH" + fi } cmd_delete() { diff --git a/git-flow-support b/git-flow-support index 4f3ccdce..77729851 100644 --- a/git-flow-support +++ b/git-flow-support @@ -243,11 +243,6 @@ F,[no]fetch Fetch from origin before performing local operation git_local_branch_exists "$BASE_BRANCH" || die "The base '$BASE_BRANCH' doesn't exists locally or is not a branch. Can't rebase the support branch '$BRANCH'." - # Update local branches with remote branches - if flag fetch; then - git_fetch_branch "$ORIGIN" "$BASE_BRANCH" - fi - git_do checkout -q "$BRANCH" || die "Could not check out branch '$BRANCH'." if flag interactive; then opts="$opts -i" @@ -255,5 +250,12 @@ F,[no]fetch Fetch from origin before performing local operation if flag preserve_merges; then opts="$opts -p" fi - git_do rebase $opts "$BASE_BRANCH" + + # Update local branches with remote branches + if flag fetch; then + git_fetch_branch "$ORIGIN" "$BASE_BRANCH" + git_do rebase $opts "$ORIGIN/$BASE_BRANCH" + else + git_do rebase $opts "$BASE_BRANCH" + fi }