@@ -206,6 +206,7 @@ static int merge_recursive(const char *base_sha1,
206206{
207207 char buffer [256 ];
208208 const char * argv [6 ];
209+ int i = 0 ;
209210
210211 sprintf (buffer , "GITHEAD_%s" , head_sha1 );
211212 setenv (buffer , head_name , 1 );
@@ -218,12 +219,13 @@ static int merge_recursive(const char *base_sha1,
218219 * and $prev on top of us (when reverting), or the change between
219220 * $prev and $commit on top of us (when cherry-picking or replaying).
220221 */
221- argv [0 ] = "merge-recursive" ;
222- argv [1 ] = base_sha1 ;
223- argv [2 ] = "--" ;
224- argv [3 ] = head_sha1 ;
225- argv [4 ] = next_sha1 ;
226- argv [5 ] = NULL ;
222+ argv [i ++ ] = "merge-recursive" ;
223+ if (base_sha1 )
224+ argv [i ++ ] = base_sha1 ;
225+ argv [i ++ ] = "--" ;
226+ argv [i ++ ] = head_sha1 ;
227+ argv [i ++ ] = next_sha1 ;
228+ argv [i ++ ] = NULL ;
227229
228230 return run_command_v_opt (argv , RUN_COMMAND_NO_STDIN | RUN_GIT_CMD );
229231}
@@ -297,9 +299,12 @@ static int revert_or_cherry_pick(int argc, const char **argv)
297299 discard_cache ();
298300 }
299301
300- if (!commit -> parents )
301- die ("Cannot %s a root commit" , me );
302- if (commit -> parents -> next ) {
302+ if (!commit -> parents ) {
303+ if (action == REVERT )
304+ die ("Cannot revert a root commit" );
305+ parent = NULL ;
306+ }
307+ else if (commit -> parents -> next ) {
303308 /* Reverting or cherry-picking a merge commit */
304309 int cnt ;
305310 struct commit_list * p ;
@@ -368,7 +373,8 @@ static int revert_or_cherry_pick(int argc, const char **argv)
368373 }
369374 }
370375
371- if (merge_recursive (sha1_to_hex (base -> object .sha1 ),
376+ if (merge_recursive (base == NULL ?
377+ NULL : sha1_to_hex (base -> object .sha1 ),
372378 sha1_to_hex (head ), "HEAD" ,
373379 sha1_to_hex (next -> object .sha1 ), oneline ) ||
374380 write_cache_as_tree (head , 0 , NULL )) {
0 commit comments