git-mv: fix directory separator treatment on Windows
PATCH 1/1 git-mv: fix directory separator treatment on Windows
From: Johannes Sixt <[email protected]>
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().
--- builtin-mv.c | 10 +++------- 1 files changed, 3 insertions(+), 7 deletions(-)
builtin-mv.c +3 -7
@@ -24,14 +24,10 @@ static const char **copy_pathspec(const char *prefix, result[count] =NULL ;for (i =0 ; i < count; i++) {int length =strlen (result[i]); -if (length >0 && result[i][length -1 ] =='/' ) { +if (length >0 &&is_dir_sep (result[i][length -1 ])) result[i] =xmemdupz (result[i], length -1 ); - } -if (base_name) { -const char *last_slash =strrchr (result[i],'/' ); -if (last_slash) - result[i] = last_slash +1 ; - } +if (base_name) + result[i] =basename ((char *)result[i]); }return get_pathspec (prefix, result); }
Signature · 1 line
1.6.3.3.1337.g9661167.dirty
Hi,
Quoted 14 lines · Johannes Sixt
From: Johannes Sixt <[email protected]>
The following invocations did not work as expected on Windows:
git mv foo\bar dest
git mv foo\ destThe 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.
Quoted 7 lines
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()andbasename().Signed-off-by Johannes Sixt <[email protected]>
ACK
Dscho