Skip to content

Commit d9244ec

Browse files
j6tgitster
authored andcommitted
Windows: do not treat a path with backslashes as a remote's nick name
On Windows, the remote repository name in, e.g., `git fetch foo\bar` is clearly not a nickname for a configured remote repository. However, the function valid_remote_nick() does not account for backslashes. Use is_dir_sep() to check for both slashes and backslashes on Windows. This was discovered while playing with Duy's patches that warn after fopen() failures. The functions that read the branches and remotes files are protected by a valid_remote_nick() check. Without this change, a Windows style absolute path is incorrectly regarded as nickname and is concatenated to a prefix and used with fopen(). This triggers warnings because a colon in a path name is not allowed: C:\Temp\gittest>git fetch C:\Temp\gittest warning: unable to access '.git/remotes/C:\Temp\gittest': Invalid argument warning: unable to access '.git/branches/C:\Temp\gittest': Invalid argument From C:\Temp\gittest * branch HEAD -> FETCH_HEAD Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e20b5b5 commit d9244ec

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

remote.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,12 @@ static int valid_remote_nick(const char *name)
645645
{
646646
if (!name[0] || is_dot_or_dotdot(name))
647647
return 0;
648-
return !strchr(name, '/'); /* no slash */
648+
649+
/* remote nicknames cannot contain slashes */
650+
while (*name)
651+
if (is_dir_sep(*name++))
652+
return 0;
653+
return 1;
649654
}
650655

651656
const char *remote_for_branch(struct branch *branch, int *explicit)

0 commit comments

Comments
 (0)