summaryrefslogtreecommitdiff
path: root/tests/index/tests.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2018-06-22 19:07:54 +0900
committerEdward Thomson <ethomson@edwardthomson.com>2018-06-29 14:54:28 +0100
commit787768c2d70dfcd1c9ebc1854b5d0f67d2e6d4d9 (patch)
tree5389dc186d1128abe049f5fb83491b50e9e51372 /tests/index/tests.c
parent5e26391a2579062bdf5d6f0efe6b03f78d28f825 (diff)
downloadlibgit2-787768c2d70dfcd1c9ebc1854b5d0f67d2e6d4d9.tar.gz
index: return a unique error code on dirty index
When the index is dirty, return GIT_EINDEXDIRTY so that consumers can identify the exact problem programatically.
Diffstat (limited to 'tests/index/tests.c')
-rw-r--r--tests/index/tests.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/index/tests.c b/tests/index/tests.c
index c2e48c9fd..d7a1cc50b 100644
--- a/tests/index/tests.c
+++ b/tests/index/tests.c
@@ -384,6 +384,28 @@ void test_index_tests__dirty_and_clean(void)
git_repository_free(repo);
}
+void test_index_tests__dirty_fails_with_error(void)
+{
+ git_repository *repo;
+ git_index *index;
+ git_index_entry entry = {{0}};
+
+ /* Index is not dirty after opening */
+ repo = cl_git_sandbox_init("testrepo");
+ cl_git_pass(git_repository_index(&index, repo));
+
+ /* Index is dirty after adding an entry */
+ entry.mode = GIT_FILEMODE_BLOB;
+ entry.path = "test.txt";
+ cl_git_pass(git_index_add_frombuffer(index, &entry, "Hi.\n", 4));
+ cl_assert(git_index_is_dirty(index));
+
+ cl_git_fail_with(GIT_EINDEXDIRTY, git_checkout_head(repo, NULL));
+
+ git_index_free(index);
+ cl_git_sandbox_cleanup();
+}
+
void test_index_tests__add_frombuffer_reset_entry(void)
{
git_index *index;