Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aebddbe

Browse files
committed
Merge pull request libgit2#3434 from ethomson/reservednames
Win32 Reserved names: don't reserve names outside the working directory
2 parents cdef1fa + 538dfc8 commit aebddbe

24 files changed

+89
-4
lines changed

src/repository.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -908,12 +908,28 @@ bool git_repository__reserved_names(
908908
buf->size = git_repository__reserved_names_win32[i].size;
909909
}
910910

911-
/* Try to add any repo-specific reserved names */
911+
/* Try to add any repo-specific reserved names - the gitlink file
912+
* within a submodule or the repository (if the repository directory
913+
* is beneath the workdir). These are typically `.git`, but should
914+
* be protected in case they are not. Note, repo and workdir paths
915+
* are always prettified to end in `/`, so a prefixcmp is safe.
916+
*/
912917
if (!repo->is_bare) {
913-
const char *reserved_path = repo->path_gitlink ?
914-
repo->path_gitlink : repo->path_repository;
918+
int (*prefixcmp)(const char *, const char *);
919+
int error, ignorecase;
915920

916-
if (reserved_names_add8dot3(repo, reserved_path) < 0)
921+
error = git_repository__cvar(
922+
&ignorecase, repo, GIT_CVAR_IGNORECASE);
923+
prefixcmp = (error || ignorecase) ? git__prefixcmp_icase :
924+
git__prefixcmp;
925+
926+
if (repo->path_gitlink &&
927+
reserved_names_add8dot3(repo, repo->path_gitlink) < 0)
928+
goto on_error;
929+
930+
if (repo->path_repository &&
931+
prefixcmp(repo->path_repository, repo->workdir) == 0 &&
932+
reserved_names_add8dot3(repo, repo->path_repository) < 0)
917933
goto on_error;
918934
}
919935
}

tests/repo/reservedname.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,27 @@ void test_repo_reservedname__submodule_pointer(void)
106106
git_repository_free(sub_repo);
107107
#endif
108108
}
109+
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.
114+
*/
115+
void test_repo_reservedname__submodule_pointer_during_create(void)
116+
{
117+
git_repository *repo;
118+
git_submodule *sm;
119+
git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
120+
git_buf url = GIT_BUF_INIT;
121+
122+
repo = setup_fixture_super();
123+
124+
cl_git_pass(git_buf_joinpath(&url, clar_sandbox_path(), "sub.git"));
125+
cl_repo_set_string(repo, "submodule.sub.url", url.ptr);
126+
127+
cl_git_pass(git_submodule_lookup(&sm, repo, "sub"));
128+
cl_git_pass(git_submodule_update(sm, 1, &update_options));
129+
130+
git_submodule_free(sm);
131+
git_buf_free(&url);
132+
}

tests/resources/sub.git/HEAD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master

tests/resources/sub.git/config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = false
4+
bare = false
5+
logallrefupdates = true
6+
symlinks = false
7+
ignorecase = true
8+
hideDotFiles = dotGitOnly

tests/resources/sub.git/index

405 Bytes
Binary file not shown.

tests/resources/sub.git/logs/HEAD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0000000000000000000000000000000000000000 b7a59b3f4ea13b985f8a1e0d3757d5cd3331add8 Edward Thomson <[email protected]> 1442522322 -0400 commit (initial): Initial revision
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0000000000000000000000000000000000000000 b7a59b3f4ea13b985f8a1e0d3757d5cd3331add8 Edward Thomson <[email protected]> 1442522322 -0400 commit (initial): Initial revision
22 Bytes
Binary file not shown.
28 Bytes
Binary file not shown.
132 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)