From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Denton Liu <liu.denton@gmail.com>,
Johannes Schindelin <johannes.schindelin@gmx.de>,
Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [PATCH] checkout -p: handle tree arguments correctly again
Date: Sat, 19 Dec 2020 14:55:59 +0000 [thread overview]
Message-ID: <pull.819.git.1608389760050.gitgitgadget@gmail.com> (raw)
From: Johannes Schindelin <johannes.schindelin@gmx.de>
This fixes a segmentation fault.
The bug is caused by dereferencing `new_branch_info->commit` when it is
`NULL`, which is the case when the tree-ish argument is actually a tree,
not a commit-ish. This was introduced in 5602b500c3c (builtin/checkout:
fix `git checkout -p HEAD...` bug, 2020-10-07), where we tried to ensure
that the special tree-ish `HEAD...` is handled correctly.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
checkout -p: handle tree arguments correctly again
I literally just ran into this segmentation fault after rebasing Git for
Windows onto -rc1, and did not really think that the regression was
introduced in the v2.30.0 cycle, but was proven wrong by my
investigation: it was introduced by v2.30.0-rc0151^23.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-819%2Fdscho%2Fcheckout-p-empty-tree-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-819/dscho/checkout-p-empty-tree-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/819
builtin/checkout.c | 2 +-
t/t2016-checkout-patch.sh | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 9b82119129a..8b567b0424d 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -482,7 +482,7 @@ static int checkout_paths(const struct checkout_opts *opts,
* properly. However, there is special logic for the HEAD case
* so we mustn't replace that.
*/
- 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 d91a329eb31..abfd586c32b 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
base-commit: 6d3ef5b467eccd2769f1aa1c555d317d3c8dc707
--
gitgitgadget
next reply other threads:[~2020-12-19 14:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-19 14:55 Johannes Schindelin via GitGitGadget [this message]
2020-12-19 15:02 ` [PATCH] checkout -p: handle tree arguments correctly again Denton Liu
2020-12-19 17:34 ` Junio C Hamano
2020-12-19 17:40 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.819.git.1608389760050.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=johannes.schindelin@gmx.de \
--cc=liu.denton@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).