Skip to content

Commit 218608c

Browse files
committed
Merge branch 'jk/has-uncommitted-changes-fix'
"git pull --rebase" on a corrupt HEAD caused a segfault. In general we substitute an empty tree object when running the in-core equivalent of the diff-index command, and the codepath has been corrected to do so as well to fix this issue. * jk/has-uncommitted-changes-fix: has_uncommitted_changes(): fall back to empty tree
2 parents ffc6fa0 + 3506dc9 commit 218608c

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

diff-lib.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,9 @@ int run_diff_index(struct rev_info *revs, int cached)
520520
struct object_array_entry *ent;
521521
uint64_t start = getnanotime();
522522

523+
if (revs->pending.nr != 1)
524+
BUG("run_diff_index must be passed exactly one tree");
525+
523526
ent = revs->pending.objects;
524527
if (diff_cache(revs, &ent->item->oid, ent->name, cached))
525528
exit(128);

t/t5520-pull.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,18 @@ test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
618618
)
619619
'
620620

621+
test_expect_success 'pull --rebase fails on corrupt HEAD' '
622+
test_when_finished "rm -rf corrupt" &&
623+
git init corrupt &&
624+
(
625+
cd corrupt &&
626+
test_commit one &&
627+
obj=$(git rev-parse --verify HEAD | sed "s#^..#&/#") &&
628+
rm -f .git/objects/$obj &&
629+
test_must_fail git pull --rebase
630+
)
631+
'
632+
621633
test_expect_success 'setup for detecting upstreamed changes' '
622634
mkdir src &&
623635
(cd src &&

wt-status.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,7 +2340,17 @@ int has_uncommitted_changes(int ignore_submodules)
23402340
if (ignore_submodules)
23412341
rev_info.diffopt.flags.ignore_submodules = 1;
23422342
rev_info.diffopt.flags.quick = 1;
2343+
23432344
add_head_to_pending(&rev_info);
2345+
if (!rev_info.pending.nr) {
2346+
/*
2347+
* We have no head (or it's corrupt); use the empty tree,
2348+
* which will complain if the index is non-empty.
2349+
*/
2350+
struct tree *tree = lookup_tree(the_hash_algo->empty_tree);
2351+
add_pending_object(&rev_info, &tree->object, "");
2352+
}
2353+
23442354
diff_setup_done(&rev_info.diffopt);
23452355
result = run_diff_index(&rev_info, 1);
23462356
return diff_result_code(&rev_info.diffopt, result);

0 commit comments

Comments
 (0)