summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-06-15 01:59:56 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2017-10-07 12:32:04 +0100
commit19e8faba79b300a5ee355e606af5d1f62b4ac930 (patch)
treea5f0fa819035a789db035ef76c4bbca8fff6a4b0
parent128c5ca930fb30fff36e1eb5ff95c61ecd074edf (diff)
downloadlibgit2-ethomson/checkout_typechange.tar.gz
checkout: test force checkout when mode changesethomson/checkout_typechange
Test that we can successfully force checkout a target when the file contents are identical, but the mode has changed.
-rw-r--r--tests/checkout/tree.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c
index b3b860c63..c3475f411 100644
--- a/tests/checkout/tree.c
+++ b/tests/checkout/tree.c
@@ -1514,6 +1514,51 @@ void test_checkout_tree__baseline_is_empty_when_no_index(void)
git_reference_free(head);
}
+void test_checkout_tree__mode_change_is_force_updated(void)
+{
+ git_index *index;
+ git_reference *head;
+ git_object *obj;
+ git_status_list *status;
+
+ if (!cl_is_chmod_supported())
+ clar__skip();
+
+ assert_on_branch(g_repo, "master");
+ 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));
+
+ cl_git_pass(git_status_list_new(&status, g_repo, NULL));
+ cl_assert_equal_i(0, git_status_list_entrycount(status));
+ git_status_list_free(status);
+
+ /* update the mode on-disk */
+ cl_must_pass(p_chmod("testrepo/README", 0755));
+
+ cl_git_pass(git_checkout_tree(g_repo, obj, &g_opts));
+
+ cl_git_pass(git_status_list_new(&status, g_repo, NULL));
+ cl_assert_equal_i(0, git_status_list_entrycount(status));
+ git_status_list_free(status);
+
+ /* update the mode on-disk and in the index */
+ cl_must_pass(p_chmod("testrepo/README", 0755));
+ cl_must_pass(git_index_add_bypath(index, "README"));
+
+ cl_git_pass(git_checkout_tree(g_repo, obj, &g_opts));
+
+ cl_git_pass(git_status_list_new(&status, g_repo, NULL));
+ cl_assert_equal_i(0, git_status_list_entrycount(status));
+ git_status_list_free(status);
+
+ git_object_free(obj);
+ git_reference_free(head);
+ git_index_free(index);
+}
+
void test_checkout_tree__nullopts(void)
{
cl_git_pass(git_checkout_tree(g_repo, NULL, NULL));