diff options
-rw-r--r-- | builtin/checkout.c | 6 | ||||
-rwxr-xr-x | t/t2016-checkout-patch.sh | 5 |
2 files changed, 9 insertions, 2 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c index 9a33b005cc..728c67e8ca 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -479,9 +479,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) diff --git a/t/t2016-checkout-patch.sh b/t/t2016-checkout-patch.sh index d91a329eb3..abfd586c32 100755 --- a/t/t2016-checkout-patch.sh +++ b/t/t2016-checkout-patch.sh @@ -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 |