@matheusbsbs / matheus-bagliano / commits / 32309f54ed
Fork 0

Fix command line parameter parser of revert/cherry-pick

The parser was inconsistently done, in that it did not look at the last command line parameter to see if it could be an unknown option, although it was designed to notice unknown options if they were given in positions the command expects to find them (i.e. everything except the last parameter, which ought to be <commit-ish>). This prevented a very natural invocation $ git cherry-pick --usage from issuing the usage help. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed May 22, 2007 at 22:52 UTC 32309f54ed4b71510f67f2376d755cd2733f29b1
1 file changed +5 -2
builtin-revert.c
+5 -2
@@ -45,8 +45,10 @@ static void parse_options(int argc, const char **argv)
45 if (argc < 2)
46 usage(usage_str);
47
48 - for (i = 1; i < argc - 1; i++) {
48 + for (i = 1; i < argc; i++) {
49 arg = argv[i];
50 + if (arg[0] != '-')
51 + break;
52 if (!strcmp(arg, "-n") || !strcmp(arg, "--no-commit"))
53 no_commit = 1;
54 else if (!strcmp(arg, "-e") || !strcmp(arg, "--edit"))
@@ -59,7 +61,8 @@ static void parse_options(int argc, const char **argv)
61 else if (strcmp(arg, "-r"))
62 usage(usage_str);
63 }
62 -
64 + if (i != argc - 1)
65 + usage(usage_str);
66 arg = argv[argc - 1];
67 if (get_sha1(arg, sha1))
68 die ("Cannot find '%s'", arg);