3 test_description
='git grep --open-files-in-pager
6 TEST_PASSES_SANITIZE_LEAK
=true
8 .
"$TEST_DIRECTORY"/lib-pager.sh
11 test_expect_success
'setup' '
12 test_commit initial grep.h "
24 test_commit add-user revision.c "
27 read_pathspec_from_stdin(revs, &sb, prune);
31 static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token what)
33 append_grep_pattern(&revs->grep_filter, ptn, \"command line\", 0, what);
37 test_commit subdir subdir/grep.c "enum grep_pat_token" &&
39 test_commit uninteresting unrelated "hello, world" &&
41 echo GREP_PATTERN >untracked
44 test_expect_success SIMPLEPAGER
'git grep -O' '
47 printf "%s\n" "$@" >pager-args
50 cat >expect.less <<-\EOF &&
54 echo grep.h >expect.notless &&
56 PATH=.:$PATH git grep -O GREP_PATTERN >out &&
58 test_cmp expect.less pager-args ||
59 test_cmp expect.notless pager-args
61 test_must_be_empty out
64 test_expect_success
'git grep -O --cached' '
65 test_must_fail git grep --cached -O GREP_PATTERN >out 2>msg &&
66 test_i18ngrep open-files-in-pager msg
69 test_expect_success
'git grep -O --no-index' '
70 rm -f expect.less pager-args out &&
71 cat >expect <<-\EOF &&
77 GIT_PAGER='\''printf "%s\n" >pager-args'\'' &&
79 git grep --no-index -O GREP_PATTERN >out
81 test_cmp expect pager-args &&
82 test_must_be_empty out
85 test_expect_success
'setup: fake "less"' '
88 printf "%s\n" "$@" >actual
93 test_expect_success
'git grep -O jumps to line in less' '
94 cat >expect <<-\EOF &&
99 GIT_PAGER=./less git grep -O GREP_PATTERN >out &&
100 test_cmp expect actual &&
101 test_must_be_empty out &&
103 git grep -O./less GREP_PATTERN >out2 &&
104 test_cmp expect actual &&
105 test_must_be_empty out2
108 test_expect_success
'modified file' '
110 cat >expect <<-\EOF &&
111 +/*enum grep_pat_token
118 test_when_finished "git reset --hard" &&
119 echo "enum grep_pat_token" >unrelated &&
120 GIT_PAGER=./less git grep -F -O "enum grep_pat_token" >out &&
121 test_cmp expect actual &&
122 test_must_be_empty out
125 test_expect_success
'copes with color settings' '
127 echo grep.h >expect &&
128 test_config color.grep always &&
129 test_config color.grep.filename yellow &&
130 test_config color.grep.separator green &&
131 git grep -O'\''printf "%s\n" >actual'\'' GREP_AND &&
132 test_cmp expect actual
135 test_expect_success
'run from subdir' '
137 echo grep.c >expect &&
142 GIT_PAGER='\''printf "%s\n" >../args'\'' &&
143 git grep -O "enum grep_pat_token" >../out &&
144 git grep -O"pwd >../dir; :" "enum grep_pat_token" >../out2
154 test_cmp expect args &&
155 test_must_be_empty out &&
156 test_must_be_empty out2