Skip to content

Commit 04cd999

Browse files
committed
Merge branch 'dl/checkout-p-merge-base'
Fix to a regression introduced during this cycle. * dl/checkout-p-merge-base: checkout -p: handle tree arguments correctly again
2 parents d076224 + 5c29f19 commit 04cd999

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

builtin/checkout.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,11 @@ static int checkout_paths(const struct checkout_opts *opts,
480480
* with the hex of the commit (whether it's in `...` form or
481481
* not) for the run_add_interactive() machinery to work
482482
* properly. However, there is special logic for the HEAD case
483-
* so we mustn't replace that.
483+
* so we mustn't replace that. Also, when we were given a
484+
* tree-object, new_branch_info->commit would be NULL, but we
485+
* do not have to do any replacement, either.
484486
*/
485-
if (rev && strcmp(rev, "HEAD"))
487+
if (rev && new_branch_info->commit && strcmp(rev, "HEAD"))
486488
rev = oid_to_hex_r(rev_oid, &new_branch_info->commit->object.oid);
487489

488490
if (opts->checkout_index && opts->checkout_worktree)

t/t2016-checkout-patch.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,9 @@ test_expect_success PERL 'none of this moved HEAD' '
123123
verify_saved_head
124124
'
125125

126+
test_expect_success PERL 'empty tree can be handled' '
127+
test_when_finished "git reset --hard" &&
128+
git checkout -p $(test_oid empty_tree) --
129+
'
130+
126131
test_done

0 commit comments

Comments
 (0)