'
        # ... as does removing a directory with tracked files with a
        # submodule.
-       test_expect_success "$command: replace directory with submodule" '
+       if test "$KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR" = 1
+       then
+               # Non fast-forward merges fail with "Directory sub1 doesn't
+               # exist. sub1" because the empty submodule directory is not
+               # created
+               RESULT="failure"
+       else
+               RESULT="success"
+       fi
+       test_expect_$RESULT "$command: replace directory with submodule" '
                prolog &&
                reset_work_tree_to replace_sub1_with_directory &&
                (
        '
        # Replacing a submodule with files in a directory must fail as the
        # submodule work tree isn't removed ...
-       test_expect_success "$command: replace submodule with a directory must fail" '
+       if test "$KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES" = 1
+       then
+               # Non fast-forward merges attempt to merge the former
+               # submodule files with the newly checked out ones in the
+               # directory of the same name while it shouldn't.
+               RESULT="failure"
+       else
+               RESULT="success"
+       fi
+       test_expect_$RESULT "$command: replace submodule with a directory must fail" '
                prolog &&
                reset_work_tree_to add_sub1 &&
                (
                )
        '
        # ... especially when it contains a .git directory.
-       test_expect_success "$command: replace submodule containing a .git directory with a directory must fail" '
+       test_expect_$RESULT "$command: replace submodule containing a .git directory with a directory must fail" '
                prolog &&
                reset_work_tree_to add_sub1 &&
                (
 
--- /dev/null
+#!/bin/sh
+
+test_description='merge can handle submodules'
+
+. ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-submodule-update.sh
+
+# merges without conflicts
+test_submodule_switch "git merge"
+
+test_submodule_switch "git merge --ff"
+
+test_submodule_switch "git merge --ff-only"
+
+KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
+KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
+test_submodule_switch "git merge --no-ff"
+
+test_done