|
Packit |
ae9e2a |
#include "clar_libgit2.h"
|
|
Packit |
ae9e2a |
#include "../submodule/submodule_helpers.h"
|
|
Packit |
ae9e2a |
#include "repository.h"
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
void test_repo_reservedname__cleanup(void)
|
|
Packit |
ae9e2a |
{
|
|
Packit |
ae9e2a |
cl_git_sandbox_cleanup();
|
|
Packit |
ae9e2a |
}
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
void test_repo_reservedname__includes_shortname_on_win32(void)
|
|
Packit |
ae9e2a |
{
|
|
Packit |
ae9e2a |
git_repository *repo;
|
|
Packit |
ae9e2a |
git_buf *reserved;
|
|
Packit |
ae9e2a |
size_t reserved_len;
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
repo = cl_git_sandbox_init("nasty");
|
|
Packit |
ae9e2a |
cl_assert(git_repository__reserved_names(&reserved, &reserved_len, repo, false));
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
#ifdef GIT_WIN32
|
|
Packit |
ae9e2a |
cl_assert_equal_i(2, reserved_len);
|
|
Packit |
ae9e2a |
cl_assert_equal_s(".git", reserved[0].ptr);
|
|
Packit |
ae9e2a |
cl_assert_equal_s("GIT~1", reserved[1].ptr);
|
|
Packit |
ae9e2a |
#else
|
|
Packit |
ae9e2a |
cl_assert_equal_i(1, reserved_len);
|
|
Packit |
ae9e2a |
cl_assert_equal_s(".git", reserved[0].ptr);
|
|
Packit |
ae9e2a |
#endif
|
|
Packit |
ae9e2a |
}
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
void test_repo_reservedname__includes_shortname_when_requested(void)
|
|
Packit |
ae9e2a |
{
|
|
Packit |
ae9e2a |
git_repository *repo;
|
|
Packit |
ae9e2a |
git_buf *reserved;
|
|
Packit |
ae9e2a |
size_t reserved_len;
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
repo = cl_git_sandbox_init("nasty");
|
|
Packit |
ae9e2a |
cl_assert(git_repository__reserved_names(&reserved, &reserved_len, repo, true));
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
cl_assert_equal_i(2, reserved_len);
|
|
Packit |
ae9e2a |
cl_assert_equal_s(".git", reserved[0].ptr);
|
|
Packit |
ae9e2a |
cl_assert_equal_s("GIT~1", reserved[1].ptr);
|
|
Packit |
ae9e2a |
}
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/* Ensures that custom shortnames are included: creates a GIT~1 so that the
|
|
Packit |
ae9e2a |
* .git folder itself will have to be named GIT~2
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
void test_repo_reservedname__custom_shortname_recognized(void)
|
|
Packit |
ae9e2a |
{
|
|
Packit |
ae9e2a |
#ifdef GIT_WIN32
|
|
Packit |
ae9e2a |
git_repository *repo;
|
|
Packit |
ae9e2a |
git_buf *reserved;
|
|
Packit |
ae9e2a |
size_t reserved_len;
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
if (!cl_sandbox_supports_8dot3())
|
|
Packit |
ae9e2a |
clar__skip();
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
repo = cl_git_sandbox_init("nasty");
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
cl_must_pass(p_rename("nasty/.git", "nasty/_temp"));
|
|
Packit |
ae9e2a |
cl_git_write2file("nasty/git~1", "", 0, O_RDWR|O_CREAT, 0666);
|
|
Packit |
ae9e2a |
cl_must_pass(p_rename("nasty/_temp", "nasty/.git"));
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
cl_assert(git_repository__reserved_names(&reserved, &reserved_len, repo, true));
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
cl_assert_equal_i(3, reserved_len);
|
|
Packit |
ae9e2a |
cl_assert_equal_s(".git", reserved[0].ptr);
|
|
Packit |
ae9e2a |
cl_assert_equal_s("GIT~1", reserved[1].ptr);
|
|
Packit |
ae9e2a |
cl_assert_equal_s("GIT~2", reserved[2].ptr);
|
|
Packit |
ae9e2a |
#endif
|
|
Packit |
ae9e2a |
}
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/* When looking at the short name for a submodule, we need to prevent
|
|
Packit |
ae9e2a |
* people from overwriting the `.git` file in the submodule working
|
|
Packit |
ae9e2a |
* directory itself. We don't want to look at the actual repository
|
|
Packit |
ae9e2a |
* path, since it will be in the super's repository above us, and
|
|
Packit |
ae9e2a |
* typically named with the name of our subrepository. Consequently,
|
|
Packit |
ae9e2a |
* preventing access to the short name of the actual repository path
|
|
Packit |
ae9e2a |
* would prevent us from creating files with the same name as the
|
|
Packit |
ae9e2a |
* subrepo. (Eg, a submodule named "libgit2" could not contain a file
|
|
Packit |
ae9e2a |
* named "libgit2", which would be unfortunate.)
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
void test_repo_reservedname__submodule_pointer(void)
|
|
Packit |
ae9e2a |
{
|
|
Packit |
ae9e2a |
#ifdef GIT_WIN32
|
|
Packit |
ae9e2a |
git_repository *super_repo, *sub_repo;
|
|
Packit |
ae9e2a |
git_submodule *sub;
|
|
Packit |
ae9e2a |
git_buf *sub_reserved;
|
|
Packit |
ae9e2a |
size_t sub_reserved_len;
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
if (!cl_sandbox_supports_8dot3())
|
|
Packit |
ae9e2a |
clar__skip();
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
super_repo = setup_fixture_submod2();
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
assert_submodule_exists(super_repo, "sm_unchanged");
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
cl_git_pass(git_submodule_lookup(&sub, super_repo, "sm_unchanged"));
|
|
Packit |
ae9e2a |
cl_git_pass(git_submodule_open(&sub_repo, sub));
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
cl_assert(git_repository__reserved_names(&sub_reserved, &sub_reserved_len, sub_repo, true));
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
cl_assert_equal_i(2, sub_reserved_len);
|
|
Packit |
ae9e2a |
cl_assert_equal_s(".git", sub_reserved[0].ptr);
|
|
Packit |
ae9e2a |
cl_assert_equal_s("GIT~1", sub_reserved[1].ptr);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
git_submodule_free(sub);
|
|
Packit |
ae9e2a |
git_repository_free(sub_repo);
|
|
Packit |
ae9e2a |
#endif
|
|
Packit |
ae9e2a |
}
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/* Like the `submodule_pointer` test (above), this ensures that we do not
|
|
Packit |
ae9e2a |
* follow the gitlink to the submodule's repository location and treat that
|
|
Packit |
ae9e2a |
* as a reserved name. This tests at an initial submodule update, where the
|
|
Packit |
ae9e2a |
* submodule repo is being created.
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
void test_repo_reservedname__submodule_pointer_during_create(void)
|
|
Packit |
ae9e2a |
{
|
|
Packit |
ae9e2a |
git_repository *repo;
|
|
Packit |
ae9e2a |
git_submodule *sm;
|
|
Packit |
ae9e2a |
git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
|
|
Packit |
ae9e2a |
git_buf url = GIT_BUF_INIT;
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
repo = setup_fixture_super();
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
cl_git_pass(git_buf_joinpath(&url, clar_sandbox_path(), "sub.git"));
|
|
Packit |
ae9e2a |
cl_repo_set_string(repo, "submodule.sub.url", url.ptr);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
cl_git_pass(git_submodule_lookup(&sm, repo, "sub"));
|
|
Packit |
ae9e2a |
cl_git_pass(git_submodule_update(sm, 1, &update_options));
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
git_submodule_free(sm);
|
|
Packit |
ae9e2a |
git_buf_free(&url;;
|
|
Packit |
ae9e2a |
}
|