t / t4209-log-pickaxe.shon commit Merge branch 'ps/stash-in-c' (e36adf7)
   1#!/bin/sh
   2
   3test_description='log --grep/--author/--regexp-ignore-case/-S/-G'
   4. ./test-lib.sh
   5
   6test_log () {
   7        expect=$1
   8        kind=$2
   9        needle=$3
  10        shift 3
  11        rest=$@
  12
  13        case $kind in
  14        --*)
  15                opt=$kind=$needle
  16                ;;
  17        *)
  18                opt=$kind$needle
  19                ;;
  20        esac
  21        case $expect in
  22        expect_nomatch)
  23                match=nomatch
  24                ;;
  25        *)
  26                match=match
  27                ;;
  28        esac
  29
  30        test_expect_success "log $kind${rest:+ $rest} ($match)" "
  31                git log $rest $opt --format=%H >actual &&
  32                test_cmp $expect actual
  33        "
  34}
  35
  36# test -i and --regexp-ignore-case and expect both to behave the same way
  37test_log_icase () {
  38        test_log $@ --regexp-ignore-case
  39        test_log $@ -i
  40}
  41
  42test_expect_success setup '
  43        >expect_nomatch &&
  44
  45        >file &&
  46        git add file &&
  47        test_tick &&
  48        git commit -m initial &&
  49        git rev-parse --verify HEAD >expect_initial &&
  50
  51        echo Picked >file &&
  52        git add file &&
  53        test_tick &&
  54        git commit --author="Another Person <another@example.com>" -m second &&
  55        git rev-parse --verify HEAD >expect_second
  56'
  57
  58test_log        expect_initial  --grep initial
  59test_log        expect_nomatch  --grep InItial
  60test_log_icase  expect_initial  --grep InItial
  61test_log_icase  expect_nomatch  --grep initail
  62
  63test_log        expect_second   --author Person
  64test_log        expect_nomatch  --author person
  65test_log_icase  expect_second   --author person
  66test_log_icase  expect_nomatch  --author spreon
  67
  68test_log        expect_nomatch  -G picked
  69test_log        expect_second   -G Picked
  70test_log_icase  expect_nomatch  -G pickle
  71test_log_icase  expect_second   -G picked
  72
  73test_expect_success 'log -G --textconv (missing textconv tool)' '
  74        echo "* diff=test" >.gitattributes &&
  75        test_must_fail git -c diff.test.textconv=missing log -Gfoo &&
  76        rm .gitattributes
  77'
  78
  79test_expect_success 'log -G --no-textconv (missing textconv tool)' '
  80        echo "* diff=test" >.gitattributes &&
  81        git -c diff.test.textconv=missing log -Gfoo --no-textconv >actual &&
  82        test_cmp expect_nomatch actual &&
  83        rm .gitattributes
  84'
  85
  86test_log        expect_nomatch  -S picked
  87test_log        expect_second   -S Picked
  88test_log_icase  expect_second   -S picked
  89test_log_icase  expect_nomatch  -S pickle
  90
  91test_log        expect_nomatch  -S p.cked --pickaxe-regex
  92test_log        expect_second   -S P.cked --pickaxe-regex
  93test_log_icase  expect_second   -S p.cked --pickaxe-regex
  94test_log_icase  expect_nomatch  -S p.ckle --pickaxe-regex
  95
  96test_expect_success 'log -S --textconv (missing textconv tool)' '
  97        echo "* diff=test" >.gitattributes &&
  98        test_must_fail git -c diff.test.textconv=missing log -Sfoo &&
  99        rm .gitattributes
 100'
 101
 102test_expect_success 'log -S --no-textconv (missing textconv tool)' '
 103        echo "* diff=test" >.gitattributes &&
 104        git -c diff.test.textconv=missing log -Sfoo --no-textconv >actual &&
 105        test_cmp expect_nomatch actual &&
 106        rm .gitattributes
 107'
 108
 109test_expect_success 'setup log -[GS] binary & --text' '
 110        git checkout --orphan GS-binary-and-text &&
 111        git read-tree --empty &&
 112        printf "a\na\0a\n" >data.bin &&
 113        git add data.bin &&
 114        git commit -m "create binary file" data.bin &&
 115        printf "a\na\0a\n" >>data.bin &&
 116        git commit -m "modify binary file" data.bin &&
 117        git rm data.bin &&
 118        git commit -m "delete binary file" data.bin &&
 119        git log >full-log
 120'
 121
 122test_expect_success 'log -G ignores binary files' '
 123        git log -Ga >log &&
 124        test_must_be_empty log
 125'
 126
 127test_expect_success 'log -G looks into binary files with -a' '
 128        git log -a -Ga >log &&
 129        test_cmp log full-log
 130'
 131
 132test_expect_success 'log -G looks into binary files with textconv filter' '
 133        test_when_finished "rm .gitattributes" &&
 134        echo "* diff=bin" >.gitattributes &&
 135        git -c diff.bin.textconv=cat log -Ga >log &&
 136        test_cmp log full-log
 137'
 138
 139test_expect_success 'log -S looks into binary files' '
 140        git log -Sa >log &&
 141        test_cmp log full-log
 142'
 143
 144test_done