summaryrefslogtreecommitdiff
path: root/builtin/mv.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2016-08-05 14:41:12 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-08-08 17:43:20 (GMT)
commit189d035e67b1f8cdbb1dbd388efd1b7434f34b04 (patch)
treea8155d6ee7d1052b8054a87945fa0152f9622f17 /builtin/mv.c
parent08df31eeccfe1576971ea4ba42570a424c3cfc41 (diff)
downloadgit-189d035e67b1f8cdbb1dbd388efd1b7434f34b04.zip
git-189d035e67b1f8cdbb1dbd388efd1b7434f34b04.tar.gz
git-189d035e67b1f8cdbb1dbd388efd1b7434f34b04.tar.bz2
git mv: do not keep slash in `git mv dir non-existing-dir/`
When calling `rename("dir", "non-existing-dir/")` on Linux, it silently succeeds, stripping the trailing slash of the second argument. This is all good and dandy but this behavior disagrees with the specs at http://pubs.opengroup.org/onlinepubs/9699919799/functions/rename.html that state clearly regarding the 2nd parameter (called `new`): If the `new` argument does not resolve to an existing directory entry for a file of type directory and the `new` argument contains at least one non- <slash> character and ends with one or more trailing <slash> characters after all symbolic links have been processed, `rename()` shall fail. Of course, we would like `git mv dir non-existing-dir/` to succeed (and rename the directory "dir" to "non-existing-dir"). Let's be extra careful to remove the trailing slash in that case. This lets t7001-mv.sh pass in Bash on Windows. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/mv.c')
-rw-r--r--builtin/mv.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/builtin/mv.c b/builtin/mv.c
index a201426..446a316 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')