@@ -3561,6 +3561,7 @@ static int three_way_merge(struct apply_state *state,
35613561 const struct object_id * theirs )
35623562{
35633563 mmfile_t base_file , our_file , their_file ;
3564+ struct ll_merge_options merge_opts = LL_MERGE_OPTIONS_INIT ;
35643565 mmbuffer_t result = { NULL };
35653566 enum ll_merge_result status ;
35663567
@@ -3573,12 +3574,13 @@ static int three_way_merge(struct apply_state *state,
35733574 read_mmblob (& base_file , base );
35743575 read_mmblob (& our_file , ours );
35753576 read_mmblob (& their_file , theirs );
3577+ merge_opts .variant = state -> merge_variant ;
35763578 status = ll_merge (& result , path ,
35773579 & base_file , "base" ,
35783580 & our_file , "ours" ,
35793581 & their_file , "theirs" ,
35803582 state -> repo -> index ,
3581- NULL );
3583+ & merge_opts );
35823584 if (status == LL_MERGE_BINARY_CONFLICT )
35833585 warning ("Cannot merge binary files: %s (%s vs. %s)" ,
35843586 path , "ours" , "theirs" );
@@ -5151,6 +5153,15 @@ int apply_parse_options(int argc, const char **argv,
51515153 N_ ("also apply the patch (use with --stat/--summary/--check)" )),
51525154 OPT_BOOL ('3' , "3way" , & state -> threeway ,
51535155 N_ ( "attempt three-way merge, fall back on normal patch if that fails" )),
5156+ OPT_SET_INT_F (0 , "ours" , & state -> merge_variant ,
5157+ N_ ("for conflicts, use our version" ),
5158+ XDL_MERGE_FAVOR_OURS , PARSE_OPT_NONEG ),
5159+ OPT_SET_INT_F (0 , "theirs" , & state -> merge_variant ,
5160+ N_ ("for conflicts, use their version" ),
5161+ XDL_MERGE_FAVOR_THEIRS , PARSE_OPT_NONEG ),
5162+ OPT_SET_INT_F (0 , "union" , & state -> merge_variant ,
5163+ N_ ("for conflicts, use a union version" ),
5164+ XDL_MERGE_FAVOR_UNION , PARSE_OPT_NONEG ),
51545165 OPT_FILENAME (0 , "build-fake-ancestor" , & state -> fake_ancestor ,
51555166 N_ ("build a temporary index based on embedded index information" )),
51565167 /* Think twice before adding "--nul" synonym to this */
@@ -5190,5 +5201,10 @@ int apply_parse_options(int argc, const char **argv,
51905201 OPT_END ()
51915202 };
51925203
5193- return parse_options (argc , argv , state -> prefix , builtin_apply_options , apply_usage , 0 );
5204+ argc = parse_options (argc , argv , state -> prefix , builtin_apply_options , apply_usage , 0 );
5205+
5206+ if (state -> merge_variant && !state -> threeway )
5207+ die (_ ("--ours, --theirs, and --union require --3way" ));
5208+
5209+ return argc ;
51945210}
0 commit comments