t / t7002-grep.shon commit Merge branch 'maint-1.6.1' into maint-1.6.2 (9b7dc71)
   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
  29test_expect_success 'grep should not segfault with a bad input' '
  30        test_must_fail git grep "("
  31'
  32
  33for H in HEAD ''
  34do
  35        case "$H" in
  36        HEAD)   HC='HEAD:' L='HEAD' ;;
  37        '')     HC= L='in working tree' ;;
  38        esac
  39
  40        test_expect_success "grep -w $L" '
  41                {
  42                        echo ${HC}file:1:foo mmap bar
  43                        echo ${HC}file:3:foo_mmap bar mmap
  44                        echo ${HC}file:4:foo mmap bar_mmap
  45                        echo ${HC}file:5:foo_mmap bar mmap baz
  46                } >expected &&
  47                git grep -n -w -e mmap $H >actual &&
  48                diff expected actual
  49        '
  50
  51        test_expect_success "grep -w $L (x)" '
  52                {
  53                        echo ${HC}x:1:x x xx x
  54                } >expected &&
  55                git grep -n -w -e "x xx* x" $H >actual &&
  56                diff expected actual
  57        '
  58
  59        test_expect_success "grep -w $L (y-1)" '
  60                {
  61                        echo ${HC}y:1:y yy
  62                } >expected &&
  63                git grep -n -w -e "^y" $H >actual &&
  64                diff expected actual
  65        '
  66
  67        test_expect_success "grep -w $L (y-2)" '
  68                : >expected &&
  69                if git grep -n -w -e "^y y" $H >actual
  70                then
  71                        echo should not have matched
  72                        cat actual
  73                        false
  74                else
  75                        diff expected actual
  76                fi
  77        '
  78
  79        test_expect_success "grep -w $L (z)" '
  80                : >expected &&
  81                if git grep -n -w -e "^z" $H >actual
  82                then
  83                        echo should not have matched
  84                        cat actual
  85                        false
  86                else
  87                        diff expected actual
  88                fi
  89        '
  90
  91        test_expect_success "grep $L (t-1)" '
  92                echo "${HC}t/t:1:test" >expected &&
  93                git grep -n -e test $H >actual &&
  94                diff expected actual
  95        '
  96
  97        test_expect_success "grep $L (t-2)" '
  98                echo "${HC}t:1:test" >expected &&
  99                (
 100                        cd t &&
 101                        git grep -n -e test $H
 102                ) >actual &&
 103                diff expected actual
 104        '
 105
 106        test_expect_success "grep $L (t-3)" '
 107                echo "${HC}t/t:1:test" >expected &&
 108                (
 109                        cd t &&
 110                        git grep --full-name -n -e test $H
 111                ) >actual &&
 112                diff expected actual
 113        '
 114
 115        test_expect_success "grep -c $L (no /dev/null)" '
 116                ! git grep -c test $H | grep /dev/null
 117        '
 118
 119done
 120
 121test_expect_success 'log grep setup' '
 122        echo a >>file &&
 123        test_tick &&
 124        GIT_AUTHOR_NAME="With * Asterisk" \
 125        GIT_AUTHOR_EMAIL="xyzzy@frotz.com" \
 126        git commit -a -m "second" &&
 127
 128        echo a >>file &&
 129        test_tick &&
 130        git commit -a -m "third"
 131
 132'
 133
 134test_expect_success 'log grep (1)' '
 135        git log --author=author --pretty=tformat:%s >actual &&
 136        ( echo third ; echo initial ) >expect &&
 137        test_cmp expect actual
 138'
 139
 140test_expect_success 'log grep (2)' '
 141        git log --author=" * " -F --pretty=tformat:%s >actual &&
 142        ( echo second ) >expect &&
 143        test_cmp expect actual
 144'
 145
 146test_expect_success 'log grep (3)' '
 147        git log --author="^A U" --pretty=tformat:%s >actual &&
 148        ( echo third ; echo initial ) >expect &&
 149        test_cmp expect actual
 150'
 151
 152test_expect_success 'log grep (4)' '
 153        git log --author="frotz\.com>$" --pretty=tformat:%s >actual &&
 154        ( echo second ) >expect &&
 155        test_cmp expect actual
 156'
 157
 158test_expect_success 'log grep (5)' '
 159        git log --author=Thor -F --grep=Thu --pretty=tformat:%s >actual &&
 160        ( echo third ; echo initial ) >expect &&
 161        test_cmp expect actual
 162'
 163
 164test_expect_success 'log grep (6)' '
 165        git log --author=-0700  --pretty=tformat:%s >actual &&
 166        >expect &&
 167        test_cmp expect actual
 168'
 169
 170test_expect_success 'grep with CE_VALID file' '
 171        git update-index --assume-unchanged t/t &&
 172        rm t/t &&
 173        test "$(git grep --no-ext-grep t)" = "t/t:test" &&
 174        git update-index --no-assume-unchanged t/t &&
 175        git checkout t/t
 176'
 177
 178test_done