Skip to content

Commit 8723880

Browse files
committed
Merge branch 'ng/add-files-to-cache-wo-rename' into next
add_files_to_cache() used diff_files() to detect only the paths that are different between the index and the working tree and add them, which does not need rename detection, which interfered with unnecessary conflicts. * ng/add-files-to-cache-wo-rename: read-cache: disable renames in add_files_to_cache
2 parents 04adce3 + c0ce433 commit 8723880

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

read-cache.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4033,6 +4033,7 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
40334033
rev.diffopt.format_callback = update_callback;
40344034
rev.diffopt.format_callback_data = &data;
40354035
rev.diffopt.flags.override_submodule_config = 1;
4036+
rev.diffopt.detect_rename = 0; /* staging worktree changes does not need renames */
40364037
rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
40374038

40384039
/*

t/t2200-add-update.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,44 @@ test_expect_success 'add -u resolves unmerged paths' '
200200
test_cmp expect actual
201201
'
202202

203+
test_expect_success 'add -u avoids rename pairing on unmerged paths' '
204+
test_create_repo rename-crash &&
205+
(
206+
cd rename-crash &&
207+
test_seq 1 100 |
208+
sed "s/.*/line &: same text/" >conflict.txt &&
209+
cp conflict.txt bystander.txt &&
210+
git add conflict.txt bystander.txt &&
211+
git commit -m "initial: two files with identical content" &&
212+
main_branch=$(git symbolic-ref --short HEAD) &&
213+
git checkout -b feature &&
214+
sed "s/^line 50:.*/line 50: FEATURE/" \
215+
conflict.txt >conflict.txt.tmp &&
216+
mv conflict.txt.tmp conflict.txt &&
217+
git add conflict.txt &&
218+
git commit -m "feature: modify line 50" &&
219+
git checkout "$main_branch" &&
220+
sed "s/^line 50:.*/line 50: MAIN/" \
221+
conflict.txt >conflict.txt.tmp &&
222+
mv conflict.txt.tmp conflict.txt &&
223+
git add conflict.txt &&
224+
git commit -m "main: modify line 50 differently" &&
225+
test_must_fail git merge feature &&
226+
rm bystander.txt &&
227+
git add -u >out &&
228+
test_must_be_empty out &&
229+
git ls-files -u >actual &&
230+
test_must_be_empty actual &&
231+
git ls-files bystander.txt conflict.txt >actual &&
232+
cat >expect <<-\EOF &&
233+
conflict.txt
234+
EOF
235+
test_cmp expect actual &&
236+
git diff-files --name-only >actual &&
237+
test_must_be_empty actual
238+
)
239+
'
240+
203241
test_expect_success '"add -u non-existent" should fail' '
204242
test_must_fail git add -u non-existent &&
205243
git ls-files >actual &&

0 commit comments

Comments
 (0)