checkout tests: validate GIT_CHECKOUT_NO_REFRESH Add tests that ensure that we re-read the on-disk image by default during checkout, but when the `GIT_CHECKOUT_NO_REFRESH` option is specified, we do _not_ re-read the index.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c
index 35c0ece..9c596b2 100644
--- a/tests/checkout/tree.c
+++ b/tests/checkout/tree.c
@@ -1564,3 +1564,67 @@ void test_checkout_tree__nullopts(void)
{
cl_git_pass(git_checkout_tree(g_repo, NULL, NULL));
}
+
+static void modify_index_ondisk(void)
+{
+ git_repository *other_repo;
+ git_index *other_index;
+ git_index_entry entry = {{0}};
+
+ cl_git_pass(git_repository_open(&other_repo, git_repository_workdir(g_repo)));
+ cl_git_pass(git_repository_index(&other_index, other_repo));
+
+ cl_git_pass(git_oid_fromstr(&entry.id, "1385f264afb75a56a5bec74243be9b367ba4ca08"));
+ entry.mode = 0100644;
+ entry.path = "README";
+
+ cl_git_pass(git_index_add(other_index, &entry));
+ cl_git_pass(git_index_write(other_index));
+
+ git_index_free(other_index);
+ git_repository_free(other_repo);
+}
+
+static void modify_index_and_checkout_tree(git_checkout_options *opts)
+{
+ git_index *index;
+ git_reference *head;
+ git_object *obj;
+
+ /* External changes to the index are maintained by default */
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_git_pass(git_repository_head(&head, g_repo));
+ cl_git_pass(git_reference_peel(&obj, head, GIT_OBJ_COMMIT));
+
+ cl_git_pass(git_reset(g_repo, obj, GIT_RESET_HARD, NULL));
+ assert_status_entrycount(g_repo, 0);
+
+ modify_index_ondisk();
+
+ /* The file in the index remains modified */
+ cl_git_pass(git_checkout_tree(g_repo, obj, opts));
+
+ git_object_free(obj);
+ git_reference_free(head);
+ git_index_free(index);
+}
+
+void test_checkout_tree__retains_external_index_changes(void)
+{
+ git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE;
+
+ modify_index_and_checkout_tree(&opts);
+ assert_status_entrycount(g_repo, 1);
+}
+
+void test_checkout_tree__no_index_refresh(void)
+{
+ git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
+
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_NO_REFRESH;
+
+ modify_index_and_checkout_tree(&opts);
+ assert_status_entrycount(g_repo, 0);
+}