parse-options: disable option abbreviation with PARSE_OPT_KEEP_UNKNOWN
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sun, 27 Jan 2019 00:35:24 +0000 (07:35 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 28 Jan 2019 00:28:17 +0000 (16:28 -0800)
parse-options can unambiguously find an abbreviation only if it sees
all available options. This is usually the case when you use
parse_options(). But there are other callers like blame or shortlog
which uses parse_options_start() in combination with a custom option
parser, like rev-list. parse-options cannot see all options in this
case and will get abbrev detection wrong. Disable it.

t7800 needs update because --symlink no longer expands to --symlinks
and will be passed down to git-diff, which will not recognize it. I
still think this is the correct thing to do. But if --symlink has been
actually used in the wild, we would just add an option alias for it.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
parse-options.c
t/t7800-difftool.sh
index 740ae5438f93d65d660cfec51edc56c8df145e2b..779034e1fd86ad7cbd987d859656abd4c3f782d6 100644 (file)
@@ -266,7 +266,8 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
                }
                if (!rest) {
                        /* abbreviated? */
-                       if (!strncmp(long_name, arg, arg_end - arg)) {
+                       if (!(p->flags & PARSE_OPT_KEEP_UNKNOWN) &&
+                           !strncmp(long_name, arg, arg_end - arg)) {
 is_abbreviated:
                                if (abbrev_option) {
                                        /*
index 22b9199d599284e9fcf5d7451b98db7ee99fffbe..bb9a7f4ff91120424e300f4ced821a9217b5e34e 100755 (executable)
@@ -546,7 +546,7 @@ do
 done >actual
 EOF
 
-test_expect_success SYMLINKS 'difftool --dir-diff --symlink without unstaged changes' '
+test_expect_success SYMLINKS 'difftool --dir-diff --symlinks without unstaged changes' '
        cat >expect <<-EOF &&
        file
        $PWD/file
@@ -555,7 +555,7 @@ test_expect_success SYMLINKS 'difftool --dir-diff --symlink without unstaged cha
        sub/sub
        $PWD/sub/sub
        EOF
-       git difftool --dir-diff --symlink \
+       git difftool --dir-diff --symlinks \
                --extcmd "./.git/CHECK_SYMLINKS" branch HEAD &&
        test_cmp expect actual
 '