t / t4003-diff-rename-1.shon commit [PATCH] Test case portability fix. (368da62)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5
   6test_description='More rename detection
   7
   8'
   9. ./test-lib.sh
  10
  11compare_diff_patch () {
  12    # When heuristics are improved, the score numbers would change.
  13    # Ignore them while comparing.
  14    sed -e '/^similarity index [0-9]*%$/d' <"$1" >.tmp-1
  15    sed -e '/^similarity index [0-9]*%$/d' <"$2" >.tmp-2
  16    diff -u .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
  17}
  18
  19test_expect_success \
  20    'prepare reference tree' \
  21    'cat ../../COPYING >COPYING &&
  22     echo frotz >rezrov &&
  23    git-update-cache --add COPYING rezrov &&
  24    tree=$(git-write-tree) &&
  25    echo $tree'
  26
  27test_expect_success \
  28    'prepare work tree' \
  29    'sed -e 's/HOWEVER/However/' <COPYING >COPYING.1 &&
  30    sed -e 's/GPL/G.P.L/g' <COPYING >COPYING.2 &&
  31    rm -f COPYING &&
  32    git-update-cache --add --remove COPYING COPYING.?'
  33
  34# tree has COPYING and rezrov.  work tree has COPYING.1 and COPYING.2,
  35# both are slightly edited, and unchanged rezrov.  So we say you
  36# copy-and-edit one, and rename-and-edit the other.  We do not say
  37# anything about rezrov.
  38
  39GIT_DIFF_OPTS=--unified=0 git-diff-cache -M -p $tree >current
  40cat >expected <<\EOF
  41diff --git a/COPYING b/COPYING.1
  42copy from COPYING
  43copy to COPYING.1
  44--- a/COPYING
  45+++ b/COPYING.1
  46@@ -6 +6 @@
  47- HOWEVER, in order to allow a migration to GPLv3 if that seems like
  48+ However, in order to allow a migration to GPLv3 if that seems like
  49diff --git a/COPYING b/COPYING.2
  50rename old COPYING
  51rename new COPYING.2
  52--- a/COPYING
  53+++ b/COPYING.2
  54@@ -2 +2 @@
  55- Note that the only valid version of the GPL as far as this project
  56+ Note that the only valid version of the G.P.L as far as this project
  57@@ -6 +6 @@
  58- HOWEVER, in order to allow a migration to GPLv3 if that seems like
  59+ HOWEVER, in order to allow a migration to G.P.Lv3 if that seems like
  60@@ -12 +12 @@
  61-       This file is licensed under the GPL v2, or a later version
  62+       This file is licensed under the G.P.L v2, or a later version
  63EOF
  64
  65test_expect_success \
  66    'validate output from rename/copy detection (#1)' \
  67    'compare_diff_patch current expected'
  68
  69test_expect_success \
  70    'prepare work tree again' \
  71    'mv COPYING.2 COPYING &&
  72     git-update-cache --add --remove COPYING COPYING.1 COPYING.2'
  73
  74# tree has COPYING and rezrov.  work tree has COPYING and COPYING.1,
  75# both are slightly edited, and unchanged rezrov.  So we say you
  76# edited one, and copy-and-edit the other.  We do not say
  77# anything about rezrov.
  78
  79GIT_DIFF_OPTS=--unified=0 git-diff-cache -C -p $tree >current
  80cat >expected <<\EOF
  81diff --git a/COPYING b/COPYING
  82--- a/COPYING
  83+++ b/COPYING
  84@@ -2 +2 @@
  85- Note that the only valid version of the GPL as far as this project
  86+ Note that the only valid version of the G.P.L as far as this project
  87@@ -6 +6 @@
  88- HOWEVER, in order to allow a migration to GPLv3 if that seems like
  89+ HOWEVER, in order to allow a migration to G.P.Lv3 if that seems like
  90@@ -12 +12 @@
  91-       This file is licensed under the GPL v2, or a later version
  92+       This file is licensed under the G.P.L v2, or a later version
  93diff --git a/COPYING b/COPYING.1
  94copy from COPYING
  95copy to COPYING.1
  96--- a/COPYING
  97+++ b/COPYING.1
  98@@ -6 +6 @@
  99- HOWEVER, in order to allow a migration to GPLv3 if that seems like
 100+ However, in order to allow a migration to GPLv3 if that seems like
 101EOF
 102
 103test_expect_success \
 104    'validate output from rename/copy detection (#2)' \
 105    'compare_diff_patch current expected'
 106
 107test_expect_success \
 108    'prepare work tree once again' \
 109    'cat ../../COPYING >COPYING &&
 110     git-update-cache --add --remove COPYING COPYING.1'
 111
 112# tree has COPYING and rezrov.  work tree has COPYING and COPYING.1,
 113# but COPYING is not edited.  We say you copy-and-edit COPYING.1; this
 114# is only possible because -C mode now reports the unmodified file to
 115# the diff-core.  Unchanged rezrov, although being fed to
 116# git-diff-cache as well, should not be mentioned.
 117
 118GIT_DIFF_OPTS=--unified=0 git-diff-cache -C -p $tree >current
 119cat >expected <<\EOF
 120diff --git a/COPYING b/COPYING.1
 121copy from COPYING
 122copy to COPYING.1
 123--- a/COPYING
 124+++ b/COPYING.1
 125@@ -6 +6 @@
 126- HOWEVER, in order to allow a migration to GPLv3 if that seems like
 127+ However, in order to allow a migration to GPLv3 if that seems like
 128EOF
 129
 130test_expect_success \
 131    'validate output from rename/copy detection (#3)' \
 132    'compare_diff_patch current expected'
 133
 134test_done