diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2015-06-19 08:31:07 -0700 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2015-06-20 15:37:32 -0400 |
commit | fc6568021c301ff4ebefe22814498ba07fe60b9c (patch) | |
tree | d1a4b756930f8fe7a04deb35fc79b1fb87c9e91a | |
parent | 9018529b4ed190484aade5971fc1c9f1bcccfc15 (diff) | |
download | libgit2-fc6568021c301ff4ebefe22814498ba07fe60b9c.tar.gz |
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).
-rw-r--r-- | tests/status/worktree.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/status/worktree.c b/tests/status/worktree.c index f8d1f7f54..56f98a882 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); +} + |