Skip to content

Commit e866ffd

Browse files
author
Junio C Hamano
committed
Merge branch 'maint'
* maint: builtin-mv: readability patch git-mv: fix off-by-one error git-mv: special case destination "."
2 parents 43134fc + 60a6bf5 commit e866ffd

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

builtin-mv.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,
2626
if (length > 0 && result[i][length - 1] == '/') {
2727
char *without_slash = xmalloc(length);
2828
memcpy(without_slash, result[i], length - 1);
29-
without_slash[length] = '\0';
29+
without_slash[length - 1] = '\0';
3030
result[i] = without_slash;
3131
}
3232
if (base_name) {
@@ -114,7 +114,10 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
114114
modes = xcalloc(count, sizeof(enum update_mode));
115115
dest_path = copy_pathspec(prefix, argv + argc - 1, 1, 0);
116116

117-
if (!lstat(dest_path[0], &st) &&
117+
if (dest_path[0][0] == '\0')
118+
/* special case: "." was normalized to "" */
119+
destination = copy_pathspec(dest_path[0], argv + i, count, 1);
120+
else if (!lstat(dest_path[0], &st) &&
118121
S_ISDIR(st.st_mode)) {
119122
dest_path[0] = add_slash(dest_path[0]);
120123
destination = copy_pathspec(dest_path[0], argv + i, count, 1);

t/t7001-mv.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,8 @@ test_expect_failure \
8282
'do not move directory over existing directory' \
8383
'mkdir path0 && mkdir path0/path2 && git-mv path2 path0'
8484

85+
test_expect_success \
86+
'move into "."' \
87+
'git-mv path1/path2/ .'
88+
8589
test_done

0 commit comments

Comments
 (0)