path: root/builtin/grep.c
diff options
authorJohannes Schindelin <>2011-02-08 06:17:24 (GMT)
committerJunio C Hamano <>2014-05-15 19:49:23 (GMT)
commitf7febbea07cf6d65f85b0cdb6684d2e3666c557e (patch)
tree8f9d850e47178466da27f95fe978151ba4ca0f06 /builtin/grep.c
parent7bbc4e8fdb33e0a8e42e77cc05460d4c4f615f4d (diff)
git grep -O -i: if the pager is 'less', pass the '-I' option
When <command> happens to be the magic string "less", today git grep -O<command> -e<pattern> helpfully passes +/<pattern> to less so you can navigate through the results within a file using the n and shift+n keystrokes. Alas, that doesn't do the right thing for a case-insensitive match, i.e. git grep -i -O<command> -e<pattern> For that case we should pass --IGNORE-CASE to "less" so that n and shift+n can move between results ignoring case in the pattern. The original patch came from msysgit and used "-i", but that was not due to lack of support for "-I" but it merely overlooked that it ought to work even when the pattern contains capital letters. Signed-off-by: Johannes Schindelin <> Signed-off-by: Stepan Kasal <> Helped-by: Jonathan Nieder <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/grep.c')
1 files changed, 3 insertions, 0 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index 63f8603..1892335 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -876,6 +876,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
if (len > 4 && is_dir_sep(pager[len - 5]))
pager += len - 4;
+ if (opt.ignore_case && !strcmp("less", pager))
+ string_list_append(&path_list, "-I");
if (!strcmp("less", pager) || !strcmp("vi", pager)) {
struct strbuf buf = STRBUF_INIT;
strbuf_addf(&buf, "+/%s%s",