@@ -852,21 +852,42 @@ static int get_octopus_merge_base(struct object_id *merge_base,
852
852
853
853
/**
854
854
* Given the current HEAD oid, the merge head returned from git-fetch and the
855
- * fork point calculated by get_rebase_fork_point(), runs git-rebase with the
856
- * appropriate arguments and returns its exit status .
855
+ * fork point calculated by get_rebase_fork_point(), compute the <newbase> and
856
+ * <upstream> arguments to use for the upcoming git-rebase invocation .
857
857
*/
858
- static int run_rebase (const struct object_id * curr_head ,
858
+ static int get_rebase_newbase_and_upstream (struct object_id * newbase ,
859
+ struct object_id * upstream ,
860
+ const struct object_id * curr_head ,
859
861
const struct object_id * merge_head ,
860
862
const struct object_id * fork_point )
861
863
{
862
- int ret ;
863
864
struct object_id oct_merge_base ;
864
- struct strvec args = STRVEC_INIT ;
865
865
866
866
if (!get_octopus_merge_base (& oct_merge_base , curr_head , merge_head , fork_point ))
867
867
if (!is_null_oid (fork_point ) && oideq (& oct_merge_base , fork_point ))
868
868
fork_point = NULL ;
869
869
870
+ if (fork_point && !is_null_oid (fork_point ))
871
+ oidcpy (upstream , fork_point );
872
+ else
873
+ oidcpy (upstream , merge_head );
874
+
875
+ oidcpy (newbase , merge_head );
876
+
877
+ return 0 ;
878
+ }
879
+
880
+ /**
881
+ * Given the <newbase> and <upstream> calculated by
882
+ * get_rebase_newbase_and_upstream(), runs git-rebase with the
883
+ * appropriate arguments and returns its exit status.
884
+ */
885
+ static int run_rebase (const struct object_id * newbase ,
886
+ const struct object_id * upstream )
887
+ {
888
+ int ret ;
889
+ struct strvec args = STRVEC_INIT ;
890
+
870
891
strvec_push (& args , "rebase" );
871
892
872
893
/* Shared options */
@@ -894,12 +915,9 @@ static int run_rebase(const struct object_id *curr_head,
894
915
warning (_ ("ignoring --verify-signatures for rebase" ));
895
916
896
917
strvec_push (& args , "--onto" );
897
- strvec_push (& args , oid_to_hex (merge_head ));
918
+ strvec_push (& args , oid_to_hex (newbase ));
898
919
899
- if (fork_point && !is_null_oid (fork_point ))
900
- strvec_push (& args , oid_to_hex (fork_point ));
901
- else
902
- strvec_push (& args , oid_to_hex (merge_head ));
920
+ strvec_push (& args , oid_to_hex (upstream ));
903
921
904
922
ret = run_command_v_opt (args .v , RUN_GIT_CMD );
905
923
strvec_clear (& args );
@@ -1011,9 +1029,15 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
1011
1029
if (opt_rebase ) {
1012
1030
int ret = 0 ;
1013
1031
int ran_ff = 0 ;
1032
+
1033
+ struct object_id newbase ;
1034
+ struct object_id upstream ;
1035
+ get_rebase_newbase_and_upstream (& newbase , & upstream , & curr_head ,
1036
+ merge_heads .oid , & rebase_fork_point );
1037
+
1014
1038
if ((recurse_submodules == RECURSE_SUBMODULES_ON ||
1015
1039
recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND ) &&
1016
- submodule_touches_in_range (the_repository , & rebase_fork_point , & curr_head ))
1040
+ submodule_touches_in_range (the_repository , & upstream , & curr_head ))
1017
1041
die (_ ("cannot rebase with locally recorded submodule modifications" ));
1018
1042
if (!autostash ) {
1019
1043
struct commit_list * list = NULL ;
@@ -1034,7 +1058,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
1034
1058
free_commit_list (list );
1035
1059
}
1036
1060
if (!ran_ff )
1037
- ret = run_rebase (& curr_head , merge_heads . oid , & rebase_fork_point );
1061
+ ret = run_rebase (& newbase , & upstream );
1038
1062
1039
1063
if (!ret && (recurse_submodules == RECURSE_SUBMODULES_ON ||
1040
1064
recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND ))
0 commit comments