summaryrefslogtreecommitdiff
path: root/tests/index/tests.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-01-17 20:49:04 -0600
committerEdward Thomson <ethomson@edwardthomson.com>2015-02-14 09:25:35 -0500
commit55798fd1536f055fc23a760c41d679fc60cd2ead (patch)
treef1633dbbdb53bab4e55fdcd024beceef855b9dde /tests/index/tests.c
parent42f98a26a5da450b3ef8600b85711112dd9860f4 (diff)
downloadlibgit2-55798fd1536f055fc23a760c41d679fc60cd2ead.tar.gz
git_indexwriter: lock then write the index
Introduce `git_indexwriter`, to allow us to lock the index while performing additional operations, then complete the write (or abort, unlocking the index).
Diffstat (limited to 'tests/index/tests.c')
-rw-r--r--tests/index/tests.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/index/tests.c b/tests/index/tests.c
index a63183e10..4cf705127 100644
--- a/tests/index/tests.c
+++ b/tests/index/tests.c
@@ -677,3 +677,24 @@ void test_index_tests__reload_while_ignoring_case(void)
git_index_free(index);
}
+
+void test_index_tests__can_lock_index(void)
+{
+ git_index *index;
+ git_indexwriter one = GIT_INDEXWRITER_INIT,
+ two = GIT_INDEXWRITER_INIT;
+
+ cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+ cl_git_pass(git_indexwriter_init(&one, index));
+
+ cl_git_fail_with(GIT_ELOCKED, git_indexwriter_init(&two, index));
+ cl_git_fail_with(GIT_ELOCKED, git_index_write(index));
+
+ cl_git_pass(git_indexwriter_commit(&one));
+
+ cl_git_pass(git_index_write(index));
+
+ git_indexwriter_cleanup(&one);
+ git_indexwriter_cleanup(&two);
+ git_index_free(index);
+}