Skip to content

Commit

Permalink
add -i (built-in): do show an error message for incorrect inputs
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dscho authored and gitster committed Nov 11, 2020
1 parent 898f807 commit d34e450
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion add-interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d34e450

Please sign in to comment.