Skip to content

Commit e81c7d4

Browse files
newrengitster
authored andcommitted
t7405: add a directory/submodule conflict
For a directory/submodule conflict, we want contents from both the directory and the submodule to be present for the user to use to resolve the conflict, but we do not want paths under the directory being written into the submodule and we do not want the merge being confused by paths under the submodule being in the way. Add testcases for these situations. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 594a867 commit e81c7d4

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

t/t7405-submodule-merge.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,4 +333,92 @@ test_expect_failure 'file/submodule conflict' '
333333
)
334334
'
335335

336+
# Directory/submodule conflict
337+
# Commit O: <empty>
338+
# Commit A: path (submodule), with sole tracked file named 'world'
339+
# Commit B1: path/file
340+
# Commit B2: path/world
341+
#
342+
# Expected from merge of A & B1:
343+
# Contents under path/ from commit B1 are renamed elsewhere; we do not
344+
# want to write files from one of our tracked directories into a submodule
345+
#
346+
# Expected from merge of A & B2:
347+
# Similar to last merge, but with a slight twist: we don't want paths
348+
# under the submodule to be treated as untracked or in the way.
349+
350+
test_expect_success 'setup directory/submodule conflict' '
351+
test_create_repo directory-submodule &&
352+
(
353+
cd directory-submodule &&
354+
355+
git commit --allow-empty -m O &&
356+
357+
git branch A &&
358+
git branch B1 &&
359+
git branch B2 &&
360+
361+
git checkout B1 &&
362+
mkdir path &&
363+
echo contents >path/file &&
364+
git add path/file &&
365+
git commit -m B1 &&
366+
367+
git checkout B2 &&
368+
mkdir path &&
369+
echo contents >path/world &&
370+
git add path/world &&
371+
git commit -m B2 &&
372+
373+
git checkout A &&
374+
test_create_repo path &&
375+
test_commit -C path hello world &&
376+
git submodule add ./path &&
377+
git commit -m A
378+
)
379+
'
380+
381+
test_expect_failure 'directory/submodule conflict; keep submodule clean' '
382+
test_when_finished "git -C directory-submodule reset --hard" &&
383+
(
384+
cd directory-submodule &&
385+
386+
git checkout A^0 &&
387+
test_must_fail git merge B1^0 &&
388+
389+
git ls-files -s >out &&
390+
test_line_count = 3 out &&
391+
git ls-files -u >out &&
392+
test_line_count = 1 out &&
393+
394+
# path/ is still a submodule
395+
test_path_is_dir path/.git &&
396+
397+
echo Checking if contents from B1:path/file showed up &&
398+
# Would rather use grep -r, but that is GNU extension...
399+
git ls-files -co | xargs grep -q contents 2>/dev/null &&
400+
401+
# However, B1:path/file should NOT have shown up at path/file,
402+
# because we should not write into the submodule
403+
test_path_is_missing path/file
404+
)
405+
'
406+
407+
test_expect_failure 'directory/submodule conflict; should not treat submodule files as untracked or in the way' '
408+
test_when_finished "git -C directory-submodule/path reset --hard" &&
409+
test_when_finished "git -C directory-submodule reset --hard" &&
410+
(
411+
cd directory-submodule &&
412+
413+
git checkout A^0 &&
414+
test_must_fail git merge B2^0 >out 2>err &&
415+
416+
# We do not want files within the submodule to prevent the
417+
# merge from starting; we should not be writing to such paths
418+
# anyway.
419+
test_i18ngrep ! "refusing to lose untracked file at" err
420+
421+
)
422+
'
423+
336424
test_done

0 commit comments

Comments
 (0)