3 test_description
='git grep --open-files-in-pager
7 .
"$TEST_DIRECTORY"/lib-pager.sh
10 test_expect_success
'setup' '
11 test_commit initial grep.h "
23 test_commit add-user revision.c "
26 read_pathspec_from_stdin(revs, &sb, prune);
30 static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token what)
32 append_grep_pattern(&revs->grep_filter, ptn, \"command line\", 0, what);
36 test_commit subdir subdir/grep.c "enum grep_pat_token" &&
38 test_commit uninteresting unrelated "hello, world" &&
40 echo GREP_PATTERN >untracked
43 test_expect_success SIMPLEPAGER
'git grep -O' '
46 printf "%s\n" "$@" >pager-args
49 cat >expect.less <<-\EOF &&
53 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
64 test_expect_success
'git grep -O --cached' '
65 test_must_fail git grep --cached -O GREP_PATTERN >out 2>msg &&
66 grep 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 &&
78 GIT_PAGER='\''printf "%s\n" >pager-args'\'' &&
80 git grep --no-index -O GREP_PATTERN >out
82 test_cmp expect pager-args &&
86 test_expect_success
'setup: fake "less"' '
89 printf "%s\n" "$@" >actual
94 test_expect_success
'git grep -O jumps to line in less' '
95 cat >expect <<-\EOF &&
101 GIT_PAGER=./less git grep -O GREP_PATTERN >out &&
102 test_cmp expect actual &&
103 test_cmp empty out &&
105 git grep -O./less GREP_PATTERN >out2 &&
106 test_cmp expect actual &&
110 test_expect_success
'modified file' '
112 cat >expect <<-\EOF &&
113 +/*enum grep_pat_token
121 echo "enum grep_pat_token" >unrelated &&
122 test_when_finished "git checkout HEAD unrelated" &&
123 GIT_PAGER=./less git grep -F -O "enum grep_pat_token" >out &&
124 test_cmp expect actual &&
129 git config
"$1" "$2" &&
130 test_when_finished
"git config --unset $1"
133 test_expect_success
'copes with color settings' '
135 echo grep.h >expect &&
136 test_config color.grep always &&
137 test_config color.grep.filename yellow &&
138 test_config color.grep.separator green &&
139 git grep -O'\''printf "%s\n" >actual'\'' GREP_AND &&
140 test_cmp expect actual
143 test_expect_success
'run from subdir' '
145 echo grep.c >expect &&
151 GIT_PAGER='\''printf "%s\n" >../args'\'' &&
152 git grep -O "enum grep_pat_token" >../out &&
153 git grep -O"pwd >../dir; :" "enum grep_pat_token" >../out2
163 test_cmp expect args &&
164 test_cmp empty out &&