Skip to content

Commit 4bdbfb1

Browse files
committed
Merge branch 'mz/maint-rename-unmerged' into maint
* mz/maint-rename-unmerged: diffcore-rename: don't consider unmerged path as source
2 parents ebe8621 + d7c9bf2 commit 4bdbfb1

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

diffcore-rename.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ void diffcore_rename(struct diff_options *options)
466466
else
467467
locate_rename_dst(p->two, 1);
468468
}
469-
else if (!DIFF_FILE_VALID(p->two)) {
469+
else if (!DIFF_PAIR_UNMERGED(p) && !DIFF_FILE_VALID(p->two)) {
470470
/*
471471
* If the source is a broken "delete", and
472472
* they did not really want to get broken,
@@ -586,7 +586,10 @@ void diffcore_rename(struct diff_options *options)
586586
struct diff_filepair *p = q->queue[i];
587587
struct diff_filepair *pair_to_free = NULL;
588588

589-
if (!DIFF_FILE_VALID(p->one) && DIFF_FILE_VALID(p->two)) {
589+
if (DIFF_PAIR_UNMERGED(p)) {
590+
diff_q(&outq, p);
591+
}
592+
else if (!DIFF_FILE_VALID(p->one) && DIFF_FILE_VALID(p->two)) {
590593
/*
591594
* Creation
592595
*

t/t7060-wtstatus.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,66 @@ test_expect_success C_LOCALE_OUTPUT 'M/D conflict does not segfault' '
5656
)
5757
'
5858

59+
test_expect_success 'rename & unmerged setup' '
60+
git rm -f -r . &&
61+
cat "$TEST_DIRECTORY/README" >ONE &&
62+
git add ONE &&
63+
test_tick &&
64+
git commit -m "One commit with ONE" &&
65+
66+
echo Modified >TWO &&
67+
cat ONE >>TWO &&
68+
cat ONE >>THREE &&
69+
git add TWO THREE &&
70+
sha1=$(git rev-parse :ONE) &&
71+
git rm --cached ONE &&
72+
(
73+
echo "100644 $sha1 1 ONE" &&
74+
echo "100644 $sha1 2 ONE" &&
75+
echo "100644 $sha1 3 ONE"
76+
) | git update-index --index-info &&
77+
echo Further >>THREE
78+
'
79+
80+
test_expect_success 'rename & unmerged status' '
81+
git status -suno >actual &&
82+
cat >expect <<-EOF &&
83+
UU ONE
84+
AM THREE
85+
A TWO
86+
EOF
87+
test_cmp expect actual
88+
'
89+
90+
test_expect_success 'git diff-index --cached shows 2 added + 1 unmerged' '
91+
cat >expected <<-EOF &&
92+
U ONE
93+
A THREE
94+
A TWO
95+
EOF
96+
git diff-index --cached --name-status HEAD >actual &&
97+
test_cmp expected actual
98+
'
99+
100+
test_expect_success 'git diff-index --cached -M shows 2 added + 1 unmerged' '
101+
cat >expected <<-EOF &&
102+
U ONE
103+
A THREE
104+
A TWO
105+
EOF
106+
git diff-index --cached --name-status HEAD >actual &&
107+
test_cmp expected actual
108+
'
109+
110+
test_expect_success 'git diff-index --cached -C shows 2 copies + 1 unmerged' '
111+
cat >expected <<-EOF &&
112+
U ONE
113+
C ONE THREE
114+
C ONE TWO
115+
EOF
116+
git diff-index --cached -C --name-status HEAD |
117+
sed "s/^C[0-9]*/C/g" >actual &&
118+
test_cmp expected actual
119+
'
120+
59121
test_done

0 commit comments

Comments
 (0)