1 #include "clar_libgit2.h"
2 #include "../submodule/submodule_helpers.h"
3 #include "repository.h"
5 void test_repo_reservedname__cleanup(void)
7 cl_git_sandbox_cleanup();
10 void test_repo_reservedname__includes_shortname_on_win32(void)
16 repo
= cl_git_sandbox_init("nasty");
17 cl_assert(git_repository__reserved_names(&reserved
, &reserved_len
, repo
, false));
20 cl_assert_equal_i(2, reserved_len
);
21 cl_assert_equal_s(".git", reserved
[0].ptr
);
22 cl_assert_equal_s("GIT~1", reserved
[1].ptr
);
24 cl_assert_equal_i(1, reserved_len
);
25 cl_assert_equal_s(".git", reserved
[0].ptr
);
29 void test_repo_reservedname__includes_shortname_when_requested(void)
35 repo
= cl_git_sandbox_init("nasty");
36 cl_assert(git_repository__reserved_names(&reserved
, &reserved_len
, repo
, true));
38 cl_assert_equal_i(2, reserved_len
);
39 cl_assert_equal_s(".git", reserved
[0].ptr
);
40 cl_assert_equal_s("GIT~1", reserved
[1].ptr
);
43 /* Ensures that custom shortnames are included: creates a GIT~1 so that the
44 * .git folder itself will have to be named GIT~2
46 void test_repo_reservedname__custom_shortname_recognized(void)
53 if (!cl_sandbox_supports_8dot3())
56 repo
= cl_git_sandbox_init("nasty");
58 cl_must_pass(p_rename("nasty/.git", "nasty/_temp"));
59 cl_git_write2file("nasty/git~1", "", 0, O_RDWR
|O_CREAT
, 0666);
60 cl_must_pass(p_rename("nasty/_temp", "nasty/.git"));
62 cl_assert(git_repository__reserved_names(&reserved
, &reserved_len
, repo
, true));
64 cl_assert_equal_i(3, reserved_len
);
65 cl_assert_equal_s(".git", reserved
[0].ptr
);
66 cl_assert_equal_s("GIT~1", reserved
[1].ptr
);
67 cl_assert_equal_s("GIT~2", reserved
[2].ptr
);
71 /* When looking at the short name for a submodule, we need to prevent
72 * people from overwriting the `.git` file in the submodule working
73 * directory itself. We don't want to look at the actual repository
74 * path, since it will be in the super's repository above us, and
75 * typically named with the name of our subrepository. Consequently,
76 * preventing access to the short name of the actual repository path
77 * would prevent us from creating files with the same name as the
78 * subrepo. (Eg, a submodule named "libgit2" could not contain a file
79 * named "libgit2", which would be unfortunate.)
81 void test_repo_reservedname__submodule_pointer(void)
84 git_repository
*super_repo
, *sub_repo
;
86 git_str
*sub_reserved
;
87 size_t sub_reserved_len
;
89 if (!cl_sandbox_supports_8dot3())
92 super_repo
= setup_fixture_submod2();
94 assert_submodule_exists(super_repo
, "sm_unchanged");
96 cl_git_pass(git_submodule_lookup(&sub
, super_repo
, "sm_unchanged"));
97 cl_git_pass(git_submodule_open(&sub_repo
, sub
));
99 cl_assert(git_repository__reserved_names(&sub_reserved
, &sub_reserved_len
, sub_repo
, true));
101 cl_assert_equal_i(2, sub_reserved_len
);
102 cl_assert_equal_s(".git", sub_reserved
[0].ptr
);
103 cl_assert_equal_s("GIT~1", sub_reserved
[1].ptr
);
105 git_submodule_free(sub
);
106 git_repository_free(sub_repo
);
110 /* Like the `submodule_pointer` test (above), this ensures that we do not
111 * follow the gitlink to the submodule's repository location and treat that
112 * as a reserved name. This tests at an initial submodule update, where the
113 * submodule repo is being created.
115 void test_repo_reservedname__submodule_pointer_during_create(void)
117 git_repository
*repo
;
119 git_submodule_update_options update_options
= GIT_SUBMODULE_UPDATE_OPTIONS_INIT
;
120 git_str url
= GIT_STR_INIT
;
122 repo
= setup_fixture_super();
124 cl_git_pass(git_str_joinpath(&url
, clar_sandbox_path(), "sub.git"));
125 cl_repo_set_string(repo
, "submodule.sub.url", url
.ptr
);
127 cl_git_pass(git_submodule_lookup(&sm
, repo
, "sub"));
128 cl_git_pass(git_submodule_update(sm
, 1, &update_options
));
130 git_submodule_free(sm
);
131 git_str_dispose(&url
);