Skip to content

Commit b8f2626

Browse files
j6tgitster
authored andcommitted
git-mv: fix directory separator treatment on Windows
The following invocations did not work as expected on Windows: git mv foo\bar dest git mv foo\ dest The first command was interpreted as git mv foo/bar dest/foo/bar because the Windows style directory separator was not obeyed when the basename of 'foo\bar' was computed. The second command failed because the Windows style directory separator was not removed from the source directory, whereupon the lookup of the directory in the index failed. This fixes both issues by using is_dir_sep() and basename(). Signed-off-by: Johannes Sixt <[email protected]> Acked-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6fac1b8 commit b8f2626

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

builtin-mv.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,10 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,
2424
result[count] = NULL;
2525
for (i = 0; i < count; i++) {
2626
int length = strlen(result[i]);
27-
if (length > 0 && result[i][length - 1] == '/') {
27+
if (length > 0 && is_dir_sep(result[i][length - 1]))
2828
result[i] = xmemdupz(result[i], length - 1);
29-
}
30-
if (base_name) {
31-
const char *last_slash = strrchr(result[i], '/');
32-
if (last_slash)
33-
result[i] = last_slash + 1;
34-
}
29+
if (base_name)
30+
result[i] = basename((char *)result[i]);
3531
}
3632
return get_pathspec(prefix, result);
3733
}

0 commit comments

Comments
 (0)