Skip to content

Commit 64da3ae

Browse files
committed
checkout -m: do not try to fall back to --merge from an unborn branch
If switching from an unborn branch (= empty tree) to a valid commit failed without -m, it would fail with -m option as well. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6e8f993 commit 64da3ae

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

builtin-checkout.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static int merge_working_tree(struct checkout_opts *opts,
272272
topts.initial_checkout = is_cache_unborn();
273273
topts.update = 1;
274274
topts.merge = 1;
275-
topts.gently = opts->merge;
275+
topts.gently = opts->merge && old->commit;
276276
topts.verbose_update = !opts->quiet;
277277
topts.fn = twoway_merge;
278278
topts.dir = xcalloc(1, sizeof(*topts.dir));
@@ -294,7 +294,13 @@ static int merge_working_tree(struct checkout_opts *opts,
294294
struct tree *work;
295295
if (!opts->merge)
296296
return 1;
297-
parse_commit(old->commit);
297+
298+
/*
299+
* Without old->commit, the below is the same as
300+
* the two-tree unpack we already tried and failed.
301+
*/
302+
if (!old->commit)
303+
return 1;
298304

299305
/* Do more real merge */
300306

0 commit comments

Comments
 (0)