t / t7002-grep.shon commit Extend index to save more flags (06aaaa0)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Junio C Hamano
   4#
   5
   6test_description='git grep various.
   7'
   8
   9. ./test-lib.sh
  10
  11test_expect_success setup '
  12        {
  13                echo foo mmap bar
  14                echo foo_mmap bar
  15                echo foo_mmap bar mmap
  16                echo foo mmap bar_mmap
  17                echo foo_mmap bar mmap baz
  18        } >file &&
  19        echo x x xx x >x &&
  20        echo y yy >y &&
  21        echo zzz > z &&
  22        mkdir t &&
  23        echo test >t/t &&
  24        git add file x y z t/t &&
  25        test_tick &&
  26        git commit -m initial
  27'
  28
  29for H in HEAD ''
  30do
  31        case "$H" in
  32        HEAD)   HC='HEAD:' L='HEAD' ;;
  33        '')     HC= L='in working tree' ;;
  34        esac
  35
  36        test_expect_success "grep -w $L" '
  37                {
  38                        echo ${HC}file:1:foo mmap bar
  39                        echo ${HC}file:3:foo_mmap bar mmap
  40                        echo ${HC}file:4:foo mmap bar_mmap
  41                        echo ${HC}file:5:foo_mmap bar mmap baz
  42                } >expected &&
  43                git grep -n -w -e mmap $H >actual &&
  44                diff expected actual
  45        '
  46
  47        test_expect_success "grep -w $L (x)" '
  48                {
  49                        echo ${HC}x:1:x x xx x
  50                } >expected &&
  51                git grep -n -w -e "x xx* x" $H >actual &&
  52                diff expected actual
  53        '
  54
  55        test_expect_success "grep -w $L (y-1)" '
  56                {
  57                        echo ${HC}y:1:y yy
  58                } >expected &&
  59                git grep -n -w -e "^y" $H >actual &&
  60                diff expected actual
  61        '
  62
  63        test_expect_success "grep -w $L (y-2)" '
  64                : >expected &&
  65                if git grep -n -w -e "^y y" $H >actual
  66                then
  67                        echo should not have matched
  68                        cat actual
  69                        false
  70                else
  71                        diff expected actual
  72                fi
  73        '
  74
  75        test_expect_success "grep -w $L (z)" '
  76                : >expected &&
  77                if git grep -n -w -e "^z" $H >actual
  78                then
  79                        echo should not have matched
  80                        cat actual
  81                        false
  82                else
  83                        diff expected actual
  84                fi
  85        '
  86
  87        test_expect_success "grep $L (t-1)" '
  88                echo "${HC}t/t:1:test" >expected &&
  89                git grep -n -e test $H >actual &&
  90                diff expected actual
  91        '
  92
  93        test_expect_success "grep $L (t-2)" '
  94                echo "${HC}t:1:test" >expected &&
  95                (
  96                        cd t &&
  97                        git grep -n -e test $H
  98                ) >actual &&
  99                diff expected actual
 100        '
 101
 102        test_expect_success "grep $L (t-3)" '
 103                echo "${HC}t/t:1:test" >expected &&
 104                (
 105                        cd t &&
 106                        git grep --full-name -n -e test $H
 107                ) >actual &&
 108                diff expected actual
 109        '
 110
 111        test_expect_success "grep -c $L (no /dev/null)" '
 112                ! git grep -c test $H | grep /dev/null
 113        '
 114
 115done
 116
 117test_expect_success 'log grep setup' '
 118        echo a >>file &&
 119        test_tick &&
 120        GIT_AUTHOR_NAME="With * Asterisk" \
 121        GIT_AUTHOR_EMAIL="xyzzy@frotz.com" \
 122        git commit -a -m "second" &&
 123
 124        echo a >>file &&
 125        test_tick &&
 126        git commit -a -m "third"
 127
 128'
 129
 130test_expect_success 'log grep (1)' '
 131        git log --author=author --pretty=tformat:%s >actual &&
 132        ( echo third ; echo initial ) >expect &&
 133        test_cmp expect actual
 134'
 135
 136test_expect_success 'log grep (2)' '
 137        git log --author=" * " -F --pretty=tformat:%s >actual &&
 138        ( echo second ) >expect &&
 139        test_cmp expect actual
 140'
 141
 142test_expect_success 'log grep (3)' '
 143        git log --author="^A U" --pretty=tformat:%s >actual &&
 144        ( echo third ; echo initial ) >expect &&
 145        test_cmp expect actual
 146'
 147
 148test_expect_success 'log grep (4)' '
 149        git log --author="frotz\.com>$" --pretty=tformat:%s >actual &&
 150        ( echo second ) >expect &&
 151        test_cmp expect actual
 152'
 153
 154test_expect_success 'log grep (5)' '
 155        git log --author=Thor -F --grep=Thu --pretty=tformat:%s >actual &&
 156        ( echo third ; echo initial ) >expect &&
 157        test_cmp expect actual
 158'
 159
 160test_expect_success 'log grep (6)' '
 161        git log --author=-0700  --pretty=tformat:%s >actual &&
 162        >expect &&
 163        test_cmp expect actual
 164
 165'
 166
 167test_done