Skip to content

Commit d34e450

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 898f807 commit d34e450

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

add-interactive.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ static ssize_t find_unique(const char *string, struct prefix_item_list *list)
194194
else if (index + 1 < list->sorted.nr &&
195195
starts_with(list->sorted.items[index + 1].string, string))
196196
return -1;
197-
else if (index < list->sorted.nr)
197+
else if (index < list->sorted.nr &&
198+
starts_with(list->sorted.items[index].string, string))
198199
item = list->sorted.items[index].util;
199200
else
200201
return -1;

0 commit comments

Comments
 (0)