
When we run a test helper function in test_submodule_switch_common(), we sometimes specify a whole helper function as the $command. When we do this, in some test cases, we just mark the whole function with `test_must_fail`. However, it's possible that the helper function might fail earlier or later than expected due to an introduced bug. If this happens, then the test case will still report as passing but it should really be marked as failing since it didn't actually display the intended behaviour. Instead of invoking $command as one monolithic helper function, break it up into three parts: 1. $command which is always a git command. 2. $before which is a callback function that runs just prior to $command. 3. $after which is a callback function that runs just after $command. If the command requires a filename argument, specify it as `\$arg` since that variable will be set and the whole $command string will be eval'd. Unfortunately, there is no way to get rid of the eval as some of the commands that are passed (such as the `git pull` tests) require that no additional arguments are passed so we must have some mechanism for the caller to specify whether or not it wants the filename argument. The $before and $after callback functions will be passed the filename as the first arg. These callback functions are optional and, if missing, will be replaced with `true`. Also, in the case where we have a `test_must_fail` test, $after will not be executed, similar to how the helper functions currently behave when the git command fails and exits the &&-chain. Finally, as an added bonus, `test_must_fail` will only run on $command which is guaranteed to be a git command. An alternate design was considered where $OVERWRITING_FAIL is set from test_submodule_switch_common() and exposed to the helper function. This approach was considered too difficult to understand due to the fact that using a signalling magic environment variable might be too indirect. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
67 lines
1.4 KiB
Bash
Executable File
67 lines
1.4 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='stash can handle submodules'
|
|
|
|
. ./test-lib.sh
|
|
. "$TEST_DIRECTORY"/lib-submodule-update.sh
|
|
|
|
git_stash_before () {
|
|
git status -su >expect &&
|
|
ls -1pR * >>expect
|
|
}
|
|
|
|
git_stash_after () {
|
|
git stash &&
|
|
git status -su >actual &&
|
|
ls -1pR * >>actual &&
|
|
test_cmp expect actual &&
|
|
git stash apply
|
|
}
|
|
|
|
KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES=1
|
|
KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT=1
|
|
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
|
|
test_submodule_switch_func "read-tree -u -m \$arg" "git_stash_before" "git_stash_after"
|
|
|
|
setup_basic () {
|
|
test_when_finished "rm -rf main sub" &&
|
|
git init sub &&
|
|
(
|
|
cd sub &&
|
|
test_commit sub_file
|
|
) &&
|
|
git init main &&
|
|
(
|
|
cd main &&
|
|
git submodule add ../sub &&
|
|
test_commit main_file
|
|
)
|
|
}
|
|
|
|
test_expect_success 'stash push with submodule.recurse=true preserves dirty submodule worktree' '
|
|
setup_basic &&
|
|
(
|
|
cd main &&
|
|
git config submodule.recurse true &&
|
|
echo "x" >main_file.t &&
|
|
echo "y" >sub/sub_file.t &&
|
|
git stash push &&
|
|
test_must_fail git -C sub diff --quiet
|
|
)
|
|
'
|
|
|
|
test_expect_success 'stash push and pop with submodule.recurse=true preserves dirty submodule worktree' '
|
|
setup_basic &&
|
|
(
|
|
cd main &&
|
|
git config submodule.recurse true &&
|
|
echo "x" >main_file.t &&
|
|
echo "y" >sub/sub_file.t &&
|
|
git stash push &&
|
|
git stash pop &&
|
|
test_must_fail git -C sub diff --quiet
|
|
)
|
|
'
|
|
|
|
test_done
|