1#!/bin/sh
   2test_description='git blame corner cases'
   4. ./test-lib.sh
   5pick_fc='s/^[0-9a-f^]* *\([^ ]*\) *(\([^ ]*\) .*/\1-\2/'
   7test_expect_success setup '
   9        echo A A A A A >one &&
  11        echo B B B B B >two &&
  12        echo C C C C C >tres &&
  13        echo ABC >mouse &&
  14        git add one two tres mouse &&
  15        test_tick &&
  16        GIT_AUTHOR_NAME=Initial git commit -m Initial &&
  17        cat one >uno &&
  19        mv two dos &&
  20        cat one >>tres &&
  21        echo DEF >>mouse
  22        git add uno dos tres mouse &&
  23        test_tick &&
  24        GIT_AUTHOR_NAME=Second git commit -a -m Second &&
  25        echo GHIJK >>mouse &&
  27        git add mouse &&
  28        test_tick &&
  29        GIT_AUTHOR_NAME=Third git commit -m Third &&
  30        cat mouse >cow &&
  32        git add cow &&
  33        test_tick &&
  34        GIT_AUTHOR_NAME=Fourth git commit -m Fourth &&
  35        {
  37                echo ABC
  38                echo DEF
  39                echo XXXX
  40                echo GHIJK
  41        } >cow &&
  42        git add cow &&
  43        test_tick &&
  44        GIT_AUTHOR_NAME=Fifth git commit -m Fifth
  45'
  46test_expect_success 'straight copy without -C' '
  48        git blame uno | grep Second
  50'
  52test_expect_success 'straight move without -C' '
  54        git blame dos | grep Initial
  56'
  58test_expect_success 'straight copy with -C' '
  60        git blame -C1 uno | grep Second
  62'
  64test_expect_success 'straight move with -C' '
  66        git blame -C1 dos | grep Initial
  68'
  70test_expect_success 'straight copy with -C -C' '
  72        git blame -C -C1 uno | grep Initial
  74'
  76test_expect_success 'straight move with -C -C' '
  78        git blame -C -C1 dos | grep Initial
  80'
  82test_expect_success 'append without -C' '
  84        git blame -L2 tres | grep Second
  86'
  88test_expect_success 'append with -C' '
  90        git blame -L2 -C1 tres | grep Second
  92'
  94test_expect_success 'append with -C -C' '
  96        git blame -L2 -C -C1 tres | grep Second
  98'
 100test_expect_success 'append with -C -C -C' '
 102        git blame -L2 -C -C -C1 tres | grep Initial
 104'
 106test_expect_success 'blame wholesale copy' '
 108        git blame -f -C -C1 HEAD^ -- cow | sed -e "$pick_fc" >current &&
 110        {
 111                echo mouse-Initial
 112                echo mouse-Second
 113                echo mouse-Third
 114        } >expected &&
 115        test_cmp expected current
 116'
 118test_expect_success 'blame wholesale copy and more' '
 120        git blame -f -C -C1 HEAD -- cow | sed -e "$pick_fc" >current &&
 122        {
 123                echo mouse-Initial
 124                echo mouse-Second
 125                echo cow-Fifth
 126                echo mouse-Third
 127        } >expected &&
 128        test_cmp expected current
 129'
 131test_done