Skip to content

Commit

Permalink
Merge branch 'dl/checkout-p-merge-base'
Browse files Browse the repository at this point in the history
Fix to a regression introduced during this cycle.

* dl/checkout-p-merge-base:
  checkout -p: handle tree arguments correctly again
  • Loading branch information
gitster committed Dec 23, 2020
2 parents d076224 + 5c29f19 commit 04cd999
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,11 @@ static int checkout_paths(const struct checkout_opts *opts,
* with the hex of the commit (whether it's in `...` form or
* not) for the run_add_interactive() machinery to work
* properly. However, there is special logic for the HEAD case
* so we mustn't replace that.
* so we mustn't replace that. Also, when we were given a
* tree-object, new_branch_info->commit would be NULL, but we
* do not have to do any replacement, either.
*/
if (rev && strcmp(rev, "HEAD"))
if (rev && new_branch_info->commit && strcmp(rev, "HEAD"))
rev = oid_to_hex_r(rev_oid, &new_branch_info->commit->object.oid);

if (opts->checkout_index && opts->checkout_worktree)
Expand Down
5 changes: 5 additions & 0 deletions t/t2016-checkout-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,9 @@ test_expect_success PERL 'none of this moved HEAD' '
verify_saved_head
'

test_expect_success PERL 'empty tree can be handled' '
test_when_finished "git reset --hard" &&
git checkout -p $(test_oid empty_tree) --
'

test_done

0 comments on commit 04cd999

Please sign in to comment.