status: test that symlinks don't lose their mode Test to ensure that when status updates an index, it does not alter the original mode for file types that are not supported (eg, symlinks on Windows).
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
diff --git a/tests/status/worktree.c b/tests/status/worktree.c
index f8d1f7f..56f98a8 100644
--- a/tests/status/worktree.c
+++ b/tests/status/worktree.c
@@ -1096,3 +1096,51 @@ void test_status_worktree__unreadable_as_untracked(void)
cl_assert_equal_i(0, counts.wrong_sorted_path);
}
+void test_status_worktree__update_index_with_symlink_doesnt_change_mode(void)
+{
+ git_repository *repo = cl_git_sandbox_init("testrepo");
+ git_reference *head;
+ git_object *head_object;
+ git_index *index;
+ const git_index_entry *idx_entry;
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ status_entry_counts counts = {0};
+ const char *expected_paths[] = { "README" };
+ const unsigned int expected_statuses[] = {GIT_STATUS_WT_NEW};
+
+ opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
+ opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_UPDATE_INDEX;
+
+ cl_git_pass(git_repository_head(&head, repo));
+ cl_git_pass(git_reference_peel(&head_object, head, GIT_OBJ_COMMIT));
+
+ cl_git_pass(git_reset(repo, head_object, GIT_RESET_HARD, NULL));
+
+ cl_git_rewritefile("testrepo/README", "This was rewritten.");
+
+ /* this status rewrites the index because we have changed the
+ * contents of a tracked file
+ */
+ counts.expected_entry_count = 1;
+ counts.expected_paths = expected_paths;
+ counts.expected_statuses = expected_statuses;
+
+ cl_git_pass(
+ git_status_foreach_ext(repo, &opts, cb_status__normal, &counts));
+ cl_assert_equal_i(1, counts.entry_count);
+
+ /* now ensure that the status's rewrite of the index did not screw
+ * up the mode of the symlink `link_to_new.txt`, particularly
+ * on platforms that don't support symlinks
+ */
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_index_read(index, true));
+
+ cl_assert(idx_entry = git_index_get_bypath(index, "link_to_new.txt", 0));
+ cl_assert(S_ISLNK(idx_entry->mode));
+
+ git_index_free(index);
+ git_object_free(head_object);
+ git_reference_free(head);
+}
+