On Wed, Dec 14, 2016 at 09:37:55PM +1300, Chris Packham wrote:
> + if (continue_current_merge) {
> + int nargc = 1;
> + const char *nargv[] = {"commit", NULL};
> +
> + if (orig_argc != 2)
> + usage_msg_opt("--continue expects no arguments",
> + builtin_merge_usage, builtin_merge_options);
This message should probably be inside a _() for translation.
I noticed when running it that the output looks funny:
$ git merge --continue foo
--continue expects no arguments
usage: [...]
I was going to suggest adding something like "fatal:" here, but I
actually think it should be the responsibility of usage_msg_opt().
Looking at its other callers, they would all benefit. I posted a
patch:
http://public-inbox.org/git/[email protected]/
I also wondered what it would look like to support "--quiet" on top of
this. I don't care that much about it in particular, but I just want to
make sure we're not painting ourselves into a corner.
Here's what I came up with;
diff --git a/builtin/merge.c b/builtin/merge.c
index 668aaffb8..b13523ce9 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1160,10 +1160,16 @@ int cmd_merge(int argc, const char **argv, const char
*prefix)
show_progress = 0;
if (abort_current_merge) {
- int nargc = 2;
- const char *nargv[] = {"reset", "--merge", NULL};
+ int acceptable_arguments = 2; /* argv[0] plus --abort */
+ struct argv_array nargv = ARGV_ARRAY_INIT;
- if (orig_argc != 2)
+ argv_array_pushl(&nargv, "reset", "--merge", NULL);
+ if (verbosity < 0) {
+ acceptable_arguments++;
+ argv_array_push(&nargv, "--quiet");
+ }
+
+ if (orig_argc != acceptable_arguments)
usage_msg_opt("--abort expects no arguments",
builtin_merge_usage, builtin_merge_options);
@@ -1171,15 +1177,22 @@ int cmd_merge(int argc, const char **argv, const char
*prefix)
die(_("There is no merge to abort (MERGE_HEAD
missing)."));
/* Invoke 'git reset --merge' */
- ret = cmd_reset(nargc, nargv, prefix);
+ ret = cmd_reset(nargv.argc, nargv.argv, prefix);
+ argv_array_clear(&nargv);
goto done;
}
if (continue_current_merge) {
- int nargc = 1;
- const char *nargv[] = {"commit", NULL};
+ int acceptable_arguments = 2; /* argv[0] plus --abort */
+ struct argv_array nargv = ARGV_ARRAY_INIT;
+
+ argv_array_push(&nargv, "commit");
+ if (verbosity < 0) {
+ acceptable_arguments++;
+ argv_array_push(&nargv, "--quiet");
+ }
- if (orig_argc != 2)
+ if (orig_argc != acceptable_arguments)
usage_msg_opt("--continue expects no arguments",
builtin_merge_usage, builtin_merge_options);
@@ -1187,7 +1200,8 @@ int cmd_merge(int argc, const char **argv, const char
*prefix)
die(_("There is no merge in progress (MERGE_HEAD
missing)."));
/* Invoke 'git commit' */
- ret = cmd_commit(nargc, nargv, prefix);
+ ret = cmd_commit(nargv.argc, nargv.argv, prefix);
+ argv_array_clear(&nargv);
goto done;
}
So not too bad (and you could probably refactor it to avoid some of the
duplication). Though it does get some obscure cases wrong, like:
git merge --continue --verbose --quiet
I dunno. Maybe I am leading you down a rabbit hole, and we should just
live with silently ignoring useless options. I looked at what
cherry-pick does for this case, and its verify_opt_compatible is
somewhat scary from a maintenance standpoint. It's a whitelist, not a
blacklist, so it's easy to forget options (and it looks like "git
cherry-pick --abort -Sfoo" is missed, for example).
-Peff