Skip to content

Commit ff00b68

Browse files
committed
reset [<commit>] paths...: do not mishandle unmerged paths
Because "diff --cached HEAD" showed an incorrect blob object name on the LHS of the diff, we ended up updating the index entry with bogus value, not what we read from the tree. Noticed by John Nowak. Signed-off-by: Junio C Hamano <[email protected]>
1 parent d28790d commit ff00b68

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

builtin/reset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,
162162

163163
for (i = 0; i < q->nr; i++) {
164164
struct diff_filespec *one = q->queue[i]->one;
165-
if (one->mode) {
165+
if (one->mode && !is_null_sha1(one->sha1)) {
166166
struct cache_entry *ce;
167167
ce = make_cache_entry(one->mode, one->sha1, one->path,
168168
0, 0);

diff-lib.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ static void do_oneway_diff(struct unpack_trees_options *o,
379379
if (cached && idx && ce_stage(idx)) {
380380
struct diff_filepair *pair;
381381
pair = diff_unmerge(&revs->diffopt, idx->name);
382-
fill_filespec(pair->one, idx->sha1, idx->ce_mode);
382+
if (tree)
383+
fill_filespec(pair->one, tree->sha1, tree->ce_mode);
383384
return;
384385
}
385386

t/t7102-reset.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,21 @@ test_expect_success '--mixed refreshes the index' '
429429
test_i18ncmp expect output
430430
'
431431

432+
test_expect_success 'resetting specific path that is unmerged' '
433+
git rm --cached file2 &&
434+
F1=$(git rev-parse HEAD:file1) &&
435+
F2=$(git rev-parse HEAD:file2) &&
436+
F3=$(git rev-parse HEAD:secondfile) &&
437+
{
438+
echo "100644 $F1 1 file2" &&
439+
echo "100644 $F2 2 file2" &&
440+
echo "100644 $F3 3 file2"
441+
} | git update-index --index-info &&
442+
git ls-files -u &&
443+
test_must_fail git reset HEAD file2 &&
444+
git diff-index --exit-code --cached HEAD
445+
'
446+
432447
test_expect_success 'disambiguation (1)' '
433448
434449
git reset --hard &&

0 commit comments

Comments
 (0)