From 07b8738967a26dd7ab39d02b86aa805dea567319 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 12 Dec 2011 02:51:24 -0500 Subject: mv: honor --verbose flag The code for a verbose flag has been here since "git mv" was converted to C many years ago, but actually getting the "-v" flag from the command line was accidentally lost in the transition. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/mv.c | 1 + 1 file changed, 1 insertion(+) (limited to 'builtin') diff --git a/builtin/mv.c b/builtin/mv.c index 40f33ca4d0..449f30aaca 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -55,6 +55,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) int i, newfd; int verbose = 0, show_only = 0, force = 0, ignore_errors = 0; struct option builtin_mv_options[] = { + OPT__VERBOSE(&verbose, "be verbose"), OPT__DRY_RUN(&show_only, "dry run"), OPT__FORCE(&force, "force move/rename even if target exists"), OPT_BOOLEAN('k', NULL, &ignore_errors, "skip move/rename errors"), -- cgit v1.2.3 From 77471646d3d87691b4bcf11682945e6ccc27f9e3 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 12 Dec 2011 02:51:36 -0500 Subject: mv: make non-directory destination error more clear If you try to "git mv" multiple files onto another non-directory file, you confusingly get the "usage" message: $ touch one two three $ git add . $ git mv one two three usage: git mv [options] ... [...] From the user's perspective, that makes no sense. They just gave parameters that exactly match that usage! This behavior dates back to the original C version of "git mv", which had a usage message like: usage: git mv ( | ... ) This was slightly less confusing, because it at least mentions that there are two ways to invoke (but it still isn't clear why what the user provided doesn't work). Instead, let's show an error message like: $ git mv one two three fatal: destination 'three' is not a directory We could leave the usage message in place, too, but it doesn't actually help here. It contains no hints that there are two forms, nor that multi-file form requires that the endpoint be a directory. So it just becomes useless noise that distracts from the real error. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/mv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/mv.c b/builtin/mv.c index 449f30aaca..177e543781 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -90,7 +90,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) destination = copy_pathspec(dest_path[0], argv, argc, 1); } else { if (argc != 1) - usage_with_options(builtin_mv_usage, builtin_mv_options); + die("destination '%s' is not a directory", dest_path[0]); destination = dest_path; } -- cgit v1.2.3 From cd40b05d13676a41fc68807c351d0de07eb4c270 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 12 Dec 2011 16:54:17 -0500 Subject: mv: improve overwrite warning When we try to "git mv" over an existing file, the error message is fairly informative: $ git mv one two fatal: destination exists, source=one, destination=two When the user forces the overwrite, we give a warning: $ git mv -f one two warning: destination exists; will overwrite! This is less informative, but still sufficient in the simple rename case, as there is only one rename happening. But when moving files from one directory to another, it becomes useless: $ mkdir three $ touch one two three/one $ git add . $ git mv one two three fatal: destination exists, source=one, destination=three/one $ git mv -f one two three warning: destination exists; will overwrite! The first message is helpful, but the second one gives us no clue about what was overwritten. Let's mention the name of the destination file: $ git mv -f one two three warning: overwriting 'three/one' Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/mv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/mv.c b/builtin/mv.c index 177e543781..4a8374f63d 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -173,7 +173,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) * check both source and destination */ if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) { - warning(_("%s; will overwrite!"), bad); + warning(_("overwriting '%s'"), dst); bad = NULL; } else bad = _("Cannot overwrite"); -- cgit v1.2.3 From 534376ca04d524b99d69a30bdcf5e70ac8062aee Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 12 Dec 2011 16:54:42 -0500 Subject: mv: be quiet about overwriting When a user asks us to force a mv and overwrite the destination, we print a warning. However, since a typical use would be: $ git mv one two fatal: destination exists, source=one, destination=two $ git mv -f one two warning: overwriting 'two' this warning is just noise. We already know we're overwriting; that's why we gave -f! This patch silences the warning unless "--verbose" is given. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/mv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/mv.c b/builtin/mv.c index 4a8374f63d..10154bb316 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -173,7 +173,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix) * check both source and destination */ if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) { - warning(_("overwriting '%s'"), dst); + if (verbose) + warning(_("overwriting '%s'"), dst); bad = NULL; } else bad = _("Cannot overwrite"); -- cgit v1.2.3