Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-08-03 01:30:44 +0300
committerJunio C Hamano <gitster@pobox.com>2018-08-03 01:30:45 +0300
commitc18ac30e9ebcf7b7e2fbd992744e63c71089a12a (patch)
tree5eb5c1185b0d8bce39356abd801f0a9d7bf802ab /t
parent2b9afea37207323d629953c639542c0e4c87e484 (diff)
parent55f39cf7551bd468065306328efdb78933b36b69 (diff)
Merge branch 'en/dirty-merge-fixes'
The recursive merge strategy did not properly ensure there was no change between HEAD and the index before performing its operation, which has been corrected. * en/dirty-merge-fixes: merge: fix misleading pre-merge check documentation merge-recursive: enforce rule that index matches head before merging t6044: add more testcases with staged changes before a merge is invoked merge-recursive: fix assumption that head tree being merged is HEAD merge-recursive: make sure when we say we abort that we actually abort t6044: add a testcase for index matching head, when head doesn't match HEAD t6044: verify that merges expected to abort actually abort index_has_changes(): avoid assuming operating on the_index read-cache.c: move index_has_changes() from merge.c
Diffstat (limited to 't')
-rwxr-xr-xt/t6044-merge-unrelated-index-changes.sh67
-rwxr-xr-xt/t7504-commit-msg-hook.sh4
-rwxr-xr-xt/t7611-merge-abort.sh118
3 files changed, 60 insertions, 129 deletions
diff --git a/t/t6044-merge-unrelated-index-changes.sh b/t/t6044-merge-unrelated-index-changes.sh
index 23b86fb977..5e3779ebc9 100755
--- a/t/t6044-merge-unrelated-index-changes.sh
+++ b/t/t6044-merge-unrelated-index-changes.sh
@@ -82,7 +82,8 @@ test_expect_success 'ff update, important file modified' '
touch subdir/e &&
git add subdir/e &&
- test_must_fail git merge E^0
+ test_must_fail git merge E^0 &&
+ test_path_is_missing .git/MERGE_HEAD
'
test_expect_success 'resolve, trivial' '
@@ -91,7 +92,8 @@ test_expect_success 'resolve, trivial' '
touch random_file && git add random_file &&
- test_must_fail git merge -s resolve C^0
+ test_must_fail git merge -s resolve C^0 &&
+ test_path_is_missing .git/MERGE_HEAD
'
test_expect_success 'resolve, non-trivial' '
@@ -100,7 +102,8 @@ test_expect_success 'resolve, non-trivial' '
touch random_file && git add random_file &&
- test_must_fail git merge -s resolve D^0
+ test_must_fail git merge -s resolve D^0 &&
+ test_path_is_missing .git/MERGE_HEAD
'
test_expect_success 'recursive' '
@@ -109,7 +112,8 @@ test_expect_success 'recursive' '
touch random_file && git add random_file &&
- test_must_fail git merge -s recursive C^0
+ test_must_fail git merge -s recursive C^0 &&
+ test_path_is_missing .git/MERGE_HEAD
'
test_expect_success 'recursive, when merge branch matches merge base' '
@@ -118,7 +122,45 @@ test_expect_success 'recursive, when merge branch matches merge base' '
touch random_file && git add random_file &&
- test_must_fail git merge -s recursive F^0
+ test_must_fail git merge -s recursive F^0 &&
+ test_path_is_missing .git/MERGE_HEAD
+'
+
+test_expect_success 'merge-recursive, when index==head but head!=HEAD' '
+ git reset --hard &&
+ git checkout C^0 &&
+
+ # Make index match B
+ git diff C B -- | git apply --cached &&
+ # Merge B & F, with B as "head"
+ git merge-recursive A -- B F > out &&
+ test_i18ngrep "Already up to date" out
+'
+
+test_expect_success 'recursive, when file has staged changes not matching HEAD nor what a merge would give' '
+ git reset --hard &&
+ git checkout B^0 &&
+
+ mkdir subdir &&
+ test_seq 1 10 >subdir/a &&
+ git add subdir/a &&
+
+ # We have staged changes; merge should error out
+ test_must_fail git merge -s recursive E^0 2>err &&
+ test_i18ngrep "changes to the following files would be overwritten" err
+'
+
+test_expect_success 'recursive, when file has staged changes matching what a merge would give' '
+ git reset --hard &&
+ git checkout B^0 &&
+
+ mkdir subdir &&
+ test_seq 1 11 >subdir/a &&
+ git add subdir/a &&
+
+ # We have staged changes; merge should error out
+ test_must_fail git merge -s recursive E^0 2>err &&
+ test_i18ngrep "changes to the following files would be overwritten" err
'
test_expect_success 'octopus, unrelated file touched' '
@@ -127,7 +169,8 @@ test_expect_success 'octopus, unrelated file touched' '
touch random_file && git add random_file &&
- test_must_fail git merge C^0 D^0
+ test_must_fail git merge C^0 D^0 &&
+ test_path_is_missing .git/MERGE_HEAD
'
test_expect_success 'octopus, related file removed' '
@@ -136,7 +179,8 @@ test_expect_success 'octopus, related file removed' '
git rm b &&
- test_must_fail git merge C^0 D^0
+ test_must_fail git merge C^0 D^0 &&
+ test_path_is_missing .git/MERGE_HEAD
'
test_expect_success 'octopus, related file modified' '
@@ -145,7 +189,8 @@ test_expect_success 'octopus, related file modified' '
echo 12 >>a && git add a &&
- test_must_fail git merge C^0 D^0
+ test_must_fail git merge C^0 D^0 &&
+ test_path_is_missing .git/MERGE_HEAD
'
test_expect_success 'ours' '
@@ -154,7 +199,8 @@ test_expect_success 'ours' '
touch random_file && git add random_file &&
- test_must_fail git merge -s ours C^0
+ test_must_fail git merge -s ours C^0 &&
+ test_path_is_missing .git/MERGE_HEAD
'
test_expect_success 'subtree' '
@@ -163,7 +209,8 @@ test_expect_success 'subtree' '
touch random_file && git add random_file &&
- test_must_fail git merge -s subtree E^0
+ test_must_fail git merge -s subtree E^0 &&
+ test_path_is_missing .git/MERGE_HEAD
'
test_done
diff --git a/t/t7504-commit-msg-hook.sh b/t/t7504-commit-msg-hook.sh
index 302a3a2082..31b9c6a2c1 100755
--- a/t/t7504-commit-msg-hook.sh
+++ b/t/t7504-commit-msg-hook.sh
@@ -157,6 +157,7 @@ test_expect_success 'merge bypasses failing hook with --no-verify' '
test_when_finished "git branch -D newbranch" &&
test_when_finished "git checkout -f master" &&
git checkout --orphan newbranch &&
+ git rm -f file &&
: >file2 &&
git add file2 &&
git commit --no-verify file2 -m in-side-branch &&
@@ -168,7 +169,7 @@ test_expect_success 'merge bypasses failing hook with --no-verify' '
chmod -x "$HOOK"
test_expect_success POSIXPERM 'with non-executable hook' '
- echo "content" >> file &&
+ echo "content" >file &&
git add file &&
git commit -m "content"
@@ -249,6 +250,7 @@ test_expect_success 'hook called in git-merge picks up commit message' '
test_when_finished "git branch -D newbranch" &&
test_when_finished "git checkout -f master" &&
git checkout --orphan newbranch &&
+ git rm -f file &&
: >file2 &&
git add file2 &&
git commit --no-verify file2 -m in-side-branch &&
diff --git a/t/t7611-merge-abort.sh b/t/t7611-merge-abort.sh
index 7b4798e8e4..7c84a518aa 100755
--- a/t/t7611-merge-abort.sh
+++ b/t/t7611-merge-abort.sh
@@ -187,31 +187,6 @@ test_expect_success 'Fail clean merge with matching dirty worktree' '
test_cmp expect actual
'
-test_expect_success 'Abort clean merge with matching dirty index' '
- git add bar &&
- git diff --staged > expect &&
- git merge --no-commit clean_branch &&
- test -f .git/MERGE_HEAD &&
- ### When aborting the merge, git will discard all staged changes,
- ### including those that were staged pre-merge. In other words,
- ### --abort will LOSE any staged changes (the staged changes that
- ### are lost must match the merge result, or the merge would not
- ### have been allowed to start). Change expectations accordingly:
- rm expect &&
- touch expect &&
- # Abort merge
- git merge --abort &&
- test ! -f .git/MERGE_HEAD &&
- test "$pre_merge_head" = "$(git rev-parse HEAD)" &&
- git diff --staged > actual &&
- test_cmp expect actual &&
- test -z "$(git diff)"
-'
-
-test_expect_success 'Reset worktree changes' '
- git reset --hard "$pre_merge_head"
-'
-
test_expect_success 'Fail conflicting merge with matching dirty worktree' '
echo barf > bar &&
git diff > expect &&
@@ -223,97 +198,4 @@ test_expect_success 'Fail conflicting merge with matching dirty worktree' '
test_cmp expect actual
'
-test_expect_success 'Abort conflicting merge with matching dirty index' '
- git add bar &&
- git diff --staged > expect &&
- test_must_fail git merge conflict_branch &&
- test -f .git/MERGE_HEAD &&
- ### When aborting the merge, git will discard all staged changes,
- ### including those that were staged pre-merge. In other words,
- ### --abort will LOSE any staged changes (the staged changes that
- ### are lost must match the merge result, or the merge would not
- ### have been allowed to start). Change expectations accordingly:
- rm expect &&
- touch expect &&
- # Abort merge
- git merge --abort &&
- test ! -f .git/MERGE_HEAD &&
- test "$pre_merge_head" = "$(git rev-parse HEAD)" &&
- git diff --staged > actual &&
- test_cmp expect actual &&
- test -z "$(git diff)"
-'
-
-test_expect_success 'Reset worktree changes' '
- git reset --hard "$pre_merge_head"
-'
-
-test_expect_success 'Abort merge with pre- and post-merge worktree changes' '
- # Pre-merge worktree changes
- echo xyzzy > foo &&
- echo barf > bar &&
- git add bar &&
- git diff > expect &&
- git diff --staged > expect-staged &&
- # Perform merge
- test_must_fail git merge conflict_branch &&
- test -f .git/MERGE_HEAD &&
- # Post-merge worktree changes
- echo yzxxz > foo &&
- echo blech > baz &&
- ### When aborting the merge, git will discard staged changes (bar)
- ### and unmerged changes (baz). Other changes that are neither
- ### staged nor marked as unmerged (foo), will be preserved. For
- ### these changed, git cannot tell pre-merge changes apart from
- ### post-merge changes, so the post-merge changes will be
- ### preserved. Change expectations accordingly:
- git diff -- foo > expect &&
- rm expect-staged &&
- touch expect-staged &&
- # Abort merge
- git merge --abort &&
- test ! -f .git/MERGE_HEAD &&
- test "$pre_merge_head" = "$(git rev-parse HEAD)" &&
- git diff > actual &&
- test_cmp expect actual &&
- git diff --staged > actual-staged &&
- test_cmp expect-staged actual-staged
-'
-
-test_expect_success 'Reset worktree changes' '
- git reset --hard "$pre_merge_head"
-'
-
-test_expect_success 'Abort merge with pre- and post-merge index changes' '
- # Pre-merge worktree changes
- echo xyzzy > foo &&
- echo barf > bar &&
- git add bar &&
- git diff > expect &&
- git diff --staged > expect-staged &&
- # Perform merge
- test_must_fail git merge conflict_branch &&
- test -f .git/MERGE_HEAD &&
- # Post-merge worktree changes
- echo yzxxz > foo &&
- echo blech > baz &&
- git add foo bar &&
- ### When aborting the merge, git will discard all staged changes
- ### (foo, bar and baz), and no changes will be preserved. Whether
- ### the changes were staged pre- or post-merge does not matter
- ### (except for not preventing starting the merge).
- ### Change expectations accordingly:
- rm expect expect-staged &&
- touch expect &&
- touch expect-staged &&
- # Abort merge
- git merge --abort &&
- test ! -f .git/MERGE_HEAD &&
- test "$pre_merge_head" = "$(git rev-parse HEAD)" &&
- git diff > actual &&
- test_cmp expect actual &&
- git diff --staged > actual-staged &&
- test_cmp expect-staged actual-staged
-'
-
test_done