summaryrefslogtreecommitdiff
path: root/tests/merge
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-01-17 23:28:53 -0600
committerEdward Thomson <ethomson@edwardthomson.com>2015-02-14 09:25:35 -0500
commit8b0ddd5dd90e1d62f32faf14d5cb4bf88f04a095 (patch)
tree5b132d61f079508ae55d8ba4d7151f1335a2ce72 /tests/merge
parent8639ea5f98ac53e532820e8a186f8a1d6d98f573 (diff)
downloadlibgit2-8b0ddd5dd90e1d62f32faf14d5cb4bf88f04a095.tar.gz
merge: lock the index at the start of the merge
Always lock the index when we begin the merge, before we write any of the metdata files. This prevents a race where another client may run a commit after we have written the MERGE_HEAD but before we have updated the index, which will produce a merge commit that is treesame to one parent. The merge will finish and update the index and the resultant commit would not be a merge at all.
Diffstat (limited to 'tests/merge')
-rw-r--r--tests/merge/workdir/setup.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/merge/workdir/setup.c b/tests/merge/workdir/setup.c
index 31ffd5702..4aebf8701 100644
--- a/tests/merge/workdir/setup.c
+++ b/tests/merge/workdir/setup.c
@@ -1045,3 +1045,52 @@ void test_merge_workdir_setup__removed_after_failure(void)
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
}
+
+void test_merge_workdir_setup__unlocked_after_success(void)
+{
+ git_oid our_oid;
+ git_reference *octo1_ref;
+ git_annotated_commit *our_head, *their_heads[1];
+
+ cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
+ cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
+
+ cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
+ cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
+
+ cl_git_pass(git_merge(
+ repo, (const git_annotated_commit **)&their_heads[0], 1, NULL, NULL));
+
+ cl_assert(!git_path_exists("merge-resolve/.git/index.lock"));
+
+ git_reference_free(octo1_ref);
+
+ git_annotated_commit_free(our_head);
+ git_annotated_commit_free(their_heads[0]);
+}
+
+void test_merge_workdir_setup__unlocked_after_conflict(void)
+{
+ git_oid our_oid;
+ git_reference *octo1_ref;
+ git_annotated_commit *our_head, *their_heads[1];
+
+ cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
+ cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
+
+ cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
+ cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
+
+ cl_git_rewritefile("merge-resolve/new-in-octo1.txt",
+ "Conflicting file!\n\nMerge will fail!\n");
+
+ cl_git_fail(git_merge(
+ repo, (const git_annotated_commit **)&their_heads[0], 1, NULL, NULL));
+
+ cl_assert(!git_path_exists("merge-resolve/.git/index.lock"));
+
+ git_reference_free(octo1_ref);
+
+ git_annotated_commit_free(our_head);
+ git_annotated_commit_free(their_heads[0]);
+}