Skip to content

Commit 2db8926

Browse files
committed
Merge branch 'mz/maint-rename-unmerged'
* mz/maint-rename-unmerged: diffcore-rename: don't consider unmerged path as source
2 parents 791a765 + d7c9bf2 commit 2db8926

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
@@ -515,7 +515,7 @@ void diffcore_rename(struct diff_options *options)
515515
else
516516
locate_rename_dst(p->two, 1);
517517
}
518-
else if (!DIFF_FILE_VALID(p->two)) {
518+
else if (!DIFF_PAIR_UNMERGED(p) && !DIFF_FILE_VALID(p->two)) {
519519
/*
520520
* If the source is a broken "delete", and
521521
* they did not really want to get broken,
@@ -631,7 +631,10 @@ void diffcore_rename(struct diff_options *options)
631631
struct diff_filepair *p = q->queue[i];
632632
struct diff_filepair *pair_to_free = NULL;
633633

634-
if (!DIFF_FILE_VALID(p->one) && DIFF_FILE_VALID(p->two)) {
634+
if (DIFF_PAIR_UNMERGED(p)) {
635+
diff_q(&outq, p);
636+
}
637+
else if (!DIFF_FILE_VALID(p->one) && DIFF_FILE_VALID(p->two)) {
635638
/*
636639
* Creation
637640
*

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)