@matheusbsbs / matheus-bagliano / commits / b8f262699f
Fork 0

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 <j6t@kdbg.org> Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed Jun 30, 2009 at 15:33 UTC b8f262699f6c527b13ff95a322fafc0bfbc5a232
1 file changed +3 -7
builtin-mv.c
+3 -7
@@ -24,14 +24,10 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,
24 result[count] = NULL;
25 for (i = 0; i < count; i++) {
26 int length = strlen(result[i]);
27 - if (length > 0 && result[i][length - 1] == '/') {
27 + if (length > 0 && is_dir_sep(result[i][length - 1]))
28 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]);
31 }
32 return get_pathspec(prefix, result);
33 }