Commit aebddbe7 by Carlos Martín Nieto

Merge pull request #3434 from ethomson/reservednames

Win32 Reserved names: don't reserve names outside the working directory
parents cdef1fad 538dfc88
...@@ -908,12 +908,28 @@ bool git_repository__reserved_names( ...@@ -908,12 +908,28 @@ bool git_repository__reserved_names(
buf->size = git_repository__reserved_names_win32[i].size; buf->size = git_repository__reserved_names_win32[i].size;
} }
/* Try to add any repo-specific reserved names */ /* Try to add any repo-specific reserved names - the gitlink file
* within a submodule or the repository (if the repository directory
* is beneath the workdir). These are typically `.git`, but should
* be protected in case they are not. Note, repo and workdir paths
* are always prettified to end in `/`, so a prefixcmp is safe.
*/
if (!repo->is_bare) { if (!repo->is_bare) {
const char *reserved_path = repo->path_gitlink ? int (*prefixcmp)(const char *, const char *);
repo->path_gitlink : repo->path_repository; int error, ignorecase;
error = git_repository__cvar(
&ignorecase, repo, GIT_CVAR_IGNORECASE);
prefixcmp = (error || ignorecase) ? git__prefixcmp_icase :
git__prefixcmp;
if (repo->path_gitlink &&
reserved_names_add8dot3(repo, repo->path_gitlink) < 0)
goto on_error;
if (reserved_names_add8dot3(repo, reserved_path) < 0) if (repo->path_repository &&
prefixcmp(repo->path_repository, repo->workdir) == 0 &&
reserved_names_add8dot3(repo, repo->path_repository) < 0)
goto on_error; goto on_error;
} }
} }
......
...@@ -106,3 +106,27 @@ void test_repo_reservedname__submodule_pointer(void) ...@@ -106,3 +106,27 @@ void test_repo_reservedname__submodule_pointer(void)
git_repository_free(sub_repo); git_repository_free(sub_repo);
#endif #endif
} }
/* Like the `submodule_pointer` test (above), this ensures that we do not
* follow the gitlink to the submodule's repository location and treat that
* as a reserved name. This tests at an initial submodule update, where the
* submodule repo is being created.
*/
void test_repo_reservedname__submodule_pointer_during_create(void)
{
git_repository *repo;
git_submodule *sm;
git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
git_buf url = GIT_BUF_INIT;
repo = setup_fixture_super();
cl_git_pass(git_buf_joinpath(&url, clar_sandbox_path(), "sub.git"));
cl_repo_set_string(repo, "submodule.sub.url", url.ptr);
cl_git_pass(git_submodule_lookup(&sm, repo, "sub"));
cl_git_pass(git_submodule_update(sm, 1, &update_options));
git_submodule_free(sm);
git_buf_free(&url);
}
ref: refs/heads/master
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
0000000000000000000000000000000000000000 b7a59b3f4ea13b985f8a1e0d3757d5cd3331add8 Edward Thomson <ethomson@microsoft.com> 1442522322 -0400 commit (initial): Initial revision
0000000000000000000000000000000000000000 b7a59b3f4ea13b985f8a1e0d3757d5cd3331add8 Edward Thomson <ethomson@microsoft.com> 1442522322 -0400 commit (initial): Initial revision
b7a59b3f4ea13b985f8a1e0d3757d5cd3331add8
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
[submodule "sub"]
url = ../sub.git
79d0d58ca6aa1688a073d280169908454cad5b91
[submodule "sub"]
path = sub
url = ../sub.git
...@@ -126,6 +126,22 @@ git_repository *setup_fixture_submod2(void) ...@@ -126,6 +126,22 @@ git_repository *setup_fixture_submod2(void)
return repo; return repo;
} }
git_repository *setup_fixture_super(void)
{
git_repository *repo = cl_git_sandbox_init("super");
cl_fixture_sandbox("sub.git");
p_mkdir("super/sub", 0777);
rewrite_gitmodules(git_repository_workdir(repo));
cl_set_cleanup(cleanup_fixture_submodules, "sub.git");
cl_git_pass(git_repository_reinit_filesystem(repo, 1));
return repo;
}
git_repository *setup_fixture_submodule_simple(void) git_repository *setup_fixture_submodule_simple(void)
{ {
git_repository *repo = cl_git_sandbox_init("submodule_simple"); git_repository *repo = cl_git_sandbox_init("submodule_simple");
......
...@@ -4,6 +4,7 @@ extern void rewrite_gitmodules(const char *workdir); ...@@ -4,6 +4,7 @@ extern void rewrite_gitmodules(const char *workdir);
extern git_repository *setup_fixture_submodules(void); extern git_repository *setup_fixture_submodules(void);
extern git_repository *setup_fixture_submod2(void); extern git_repository *setup_fixture_submod2(void);
extern git_repository *setup_fixture_submodule_simple(void); extern git_repository *setup_fixture_submodule_simple(void);
extern git_repository *setup_fixture_super(void);
extern unsigned int get_submodule_status(git_repository *, const char *); extern unsigned int get_submodule_status(git_repository *, const char *);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment