Skip to content

Commit baa4adc

Browse files
pcloudsgitster
authored andcommitted
parse-options: disable option abbreviation with PARSE_OPT_KEEP_UNKNOWN
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 202fbb3 commit baa4adc

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

parse-options.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
266266
}
267267
if (!rest) {
268268
/* abbreviated? */
269-
if (!strncmp(long_name, arg, arg_end - arg)) {
269+
if (!(p->flags & PARSE_OPT_KEEP_UNKNOWN) &&
270+
!strncmp(long_name, arg, arg_end - arg)) {
270271
is_abbreviated:
271272
if (abbrev_option) {
272273
/*

t/t7800-difftool.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ do
546546
done >actual
547547
EOF
548548

549-
test_expect_success SYMLINKS 'difftool --dir-diff --symlink without unstaged changes' '
549+
test_expect_success SYMLINKS 'difftool --dir-diff --symlinks without unstaged changes' '
550550
cat >expect <<-EOF &&
551551
file
552552
$PWD/file
@@ -555,7 +555,7 @@ test_expect_success SYMLINKS 'difftool --dir-diff --symlink without unstaged cha
555555
sub/sub
556556
$PWD/sub/sub
557557
EOF
558-
git difftool --dir-diff --symlink \
558+
git difftool --dir-diff --symlinks \
559559
--extcmd "./.git/CHECK_SYMLINKS" branch HEAD &&
560560
test_cmp expect actual
561561
'

0 commit comments

Comments
 (0)