diff options
author | Johannes Schindelin <johannes.schindelin@gmx.de> | 2020-11-11 00:42:11 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-11-11 02:00:15 +0100 |
commit | d34e4502fa540ed0654df7dd75b3689c48015f1a (patch) | |
tree | 7e1d50dc7adfe2fe37610534c653093919aab0c8 /add-interactive.c | |
parent | Git 2.29.2 (diff) | |
download | git-d34e4502fa540ed0654df7dd75b3689c48015f1a.tar.xz git-d34e4502fa540ed0654df7dd75b3689c48015f1a.zip |
add -i (built-in): do show an error message for incorrect inputs
There is a neat feature in `git add -i` where it allows users to select
items via unique prefixes.
In the built-in version of `git add -i`, we specifically sort the items
(unless they are already sorted) and then perform a binary search to
figure out whether the input constitutes a unique prefix. Unfortunately,
by mistake this code misidentifies matches even if the input string is
not actually a prefix of any item.
For example, in the initial menu, where there is a `status` and an
`update` command, the input `tadaa` was mistaken as a prefix of
`update`.
Let's fix this by looking a bit closer whether the input is actually a
prefix of the item at the found insert index.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'add-interactive.c')
-rw-r--r-- | add-interactive.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/add-interactive.c b/add-interactive.c index 555c4abf32..8ca503d803 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -194,7 +194,8 @@ static ssize_t find_unique(const char *string, struct prefix_item_list *list) else if (index + 1 < list->sorted.nr && starts_with(list->sorted.items[index + 1].string, string)) return -1; - else if (index < list->sorted.nr) + else if (index < list->sorted.nr && + starts_with(list->sorted.items[index].string, string)) item = list->sorted.items[index].util; else return -1; |