diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-09-08 21:35:54 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-09-08 21:35:54 -0700 |
commit | 8e7c580e34a95576966516d2a6d45fd2c4c00180 (patch) | |
tree | 5b1a55845d3836f246269bfb7d9c0c6a3dd610ca /builtin | |
parent | 5e09f1dd30dea9647ee58556b90caefdd8533869 (diff) | |
parent | 189d035e67b1f8cdbb1dbd388efd1b7434f34b04 (diff) | |
download | git-8e7c580e34a95576966516d2a6d45fd2c4c00180.tar.gz git-8e7c580e34a95576966516d2a6d45fd2c4c00180.tar.xz |
Merge branch 'js/mv-dir-to-new-directory' into maint
"git mv dir non-existing-dir/" did not work in some environments
the same way as existing mainstream platforms. The code now moves
"dir" to "non-existing-dir", without relying on rename("A", "B/")
that strips the trailing slash of '/'.
* js/mv-dir-to-new-directory:
git mv: do not keep slash in `git mv dir non-existing-dir/`
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/mv.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/builtin/mv.c b/builtin/mv.c index a2014266b..446a31673 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -104,7 +104,7 @@ static int index_range_of_same_dir(const char *src, int length, int cmd_mv(int argc, const char **argv, const char *prefix) { - int i, gitmodules_modified = 0; + int i, flags, gitmodules_modified = 0; int verbose = 0, show_only = 0, force = 0, ignore_errors = 0; struct option builtin_mv_options[] = { OPT__VERBOSE(&verbose, N_("be verbose")), @@ -134,10 +134,13 @@ int cmd_mv(int argc, const char **argv, const char *prefix) modes = xcalloc(argc, sizeof(enum update_mode)); /* * Keep trailing slash, needed to let - * "git mv file no-such-dir/" error out. + * "git mv file no-such-dir/" error out, except in the case + * "git mv directory no-such-dir/". */ - dest_path = internal_copy_pathspec(prefix, argv + argc, 1, - KEEP_TRAILING_SLASH); + flags = KEEP_TRAILING_SLASH; + if (argc == 1 && is_directory(argv[0]) && !is_directory(argv[1])) + flags = 0; + dest_path = internal_copy_pathspec(prefix, argv + argc, 1, flags); submodule_gitfile = xcalloc(argc, sizeof(char *)); if (dest_path[0][0] == '\0') |