t / t4005-diff-rename-2.shon commit [PATCH] diff-helper: Fix R/C score parsing under -z flag. (ddafa7e)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5
   6test_description='Same rename detection as t4003 but testing diff-raw.
   7
   8'
   9. ./test-lib.sh
  10
  11_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
  12_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
  13sanitize_diff_raw='s/ '"$_x40"' '"$_x40"' \([A-Z]\)[0-9]*       / X X \1#       /'
  14compare_diff_raw () {
  15    # When heuristics are improved, the score numbers would change.
  16    # Ignore them while comparing.
  17    # Also we do not check SHA1 hash generation in this test, which
  18    # is a job for t0000-basic.sh
  19
  20    sed -e "$sanitize_diff_raw" <"$1" >.tmp-1
  21    sed -e "$sanitize_diff_raw" <"$2" >.tmp-2
  22    diff -u .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
  23}
  24
  25compare_diff_patch () {
  26    # When heuristics are improved, the score numbers would change.
  27    # Ignore them while comparing.
  28    sed -e '/^similarity index [0-9]*%$/d' <"$1" >.tmp-1
  29    sed -e '/^similarity index [0-9]*%$/d' <"$2" >.tmp-2
  30    diff -u .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
  31}
  32
  33test_expect_success \
  34    'prepare reference tree' \
  35    'cat ../../COPYING >COPYING &&
  36     echo frotz >rezrov &&
  37    git-update-cache --add COPYING rezrov &&
  38    tree=$(git-write-tree) &&
  39    echo $tree'
  40
  41test_expect_success \
  42    'prepare work tree' \
  43    'sed -e 's/HOWEVER/However/' <COPYING >COPYING.1 &&
  44    sed -e 's/GPL/G.P.L/g' <COPYING >COPYING.2 &&
  45    rm -f COPYING &&
  46    git-update-cache --add --remove COPYING COPYING.?'
  47
  48# tree has COPYING and rezrov.  work tree has COPYING.1 and COPYING.2,
  49# both are slightly edited, and unchanged rezrov.  We say COPYING.1
  50# and COPYING.2 are based on COPYING, and do not say anything about
  51# rezrov.
  52
  53git-diff-cache -M $tree >current
  54
  55cat >expected <<\EOF
  56:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234  COPYING COPYING.1
  57:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 06c67961bbaed34a127f76d261f4c0bf73eda471 R1234  COPYING COPYING.2
  58EOF
  59
  60test_expect_success \
  61    'validate output from rename/copy detection (#1)' \
  62    'compare_diff_raw current expected'
  63
  64# make sure diff-helper can grok it.
  65mv expected diff-raw
  66GIT_DIFF_OPTS=--unified=0 git-diff-helper <diff-raw >current
  67cat >expected <<\EOF
  68diff --git a/COPYING b/COPYING.1
  69copy from COPYING
  70copy to COPYING.1
  71--- a/COPYING
  72+++ b/COPYING.1
  73@@ -6 +6 @@
  74- HOWEVER, in order to allow a migration to GPLv3 if that seems like
  75+ However, in order to allow a migration to GPLv3 if that seems like
  76diff --git a/COPYING b/COPYING.2
  77rename old COPYING
  78rename new COPYING.2
  79--- a/COPYING
  80+++ b/COPYING.2
  81@@ -2 +2 @@
  82- Note that the only valid version of the GPL as far as this project
  83+ Note that the only valid version of the G.P.L as far as this project
  84@@ -6 +6 @@
  85- HOWEVER, in order to allow a migration to GPLv3 if that seems like
  86+ HOWEVER, in order to allow a migration to G.P.Lv3 if that seems like
  87@@ -12 +12 @@
  88-       This file is licensed under the GPL v2, or a later version
  89+       This file is licensed under the G.P.L v2, or a later version
  90EOF
  91
  92test_expect_success \
  93    'validate output from diff-helper (#1)' \
  94    'compare_diff_patch current expected'
  95
  96################################################################
  97
  98test_expect_success \
  99    'prepare work tree again' \
 100    'mv COPYING.2 COPYING &&
 101     git-update-cache --add --remove COPYING COPYING.1 COPYING.2'
 102
 103# tree has COPYING and rezrov.  work tree has COPYING and COPYING.1,
 104# both are slightly edited, and unchanged rezrov.  We say COPYING.1
 105# is based on COPYING and COPYING is still there, and do not say anything
 106# about rezrov.
 107
 108git-diff-cache -C $tree >current
 109cat >expected <<\EOF
 110:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 06c67961bbaed34a127f76d261f4c0bf73eda471 M      COPYING
 111:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234  COPYING COPYING.1
 112EOF
 113
 114test_expect_success \
 115    'validate output from rename/copy detection (#2)' \
 116    'compare_diff_raw current expected'
 117
 118# make sure diff-helper can grok it.
 119mv expected diff-raw
 120GIT_DIFF_OPTS=--unified=0 git-diff-helper <diff-raw >current
 121cat >expected <<\EOF
 122diff --git a/COPYING b/COPYING
 123--- a/COPYING
 124+++ b/COPYING
 125@@ -2 +2 @@
 126- Note that the only valid version of the GPL as far as this project
 127+ Note that the only valid version of the G.P.L as far as this project
 128@@ -6 +6 @@
 129- HOWEVER, in order to allow a migration to GPLv3 if that seems like
 130+ HOWEVER, in order to allow a migration to G.P.Lv3 if that seems like
 131@@ -12 +12 @@
 132-       This file is licensed under the GPL v2, or a later version
 133+       This file is licensed under the G.P.L v2, or a later version
 134diff --git a/COPYING b/COPYING.1
 135copy from COPYING
 136copy to COPYING.1
 137--- a/COPYING
 138+++ b/COPYING.1
 139@@ -6 +6 @@
 140- HOWEVER, in order to allow a migration to GPLv3 if that seems like
 141+ However, in order to allow a migration to GPLv3 if that seems like
 142EOF
 143
 144test_expect_success \
 145    'validate output from diff-helper (#2)' \
 146    'compare_diff_patch current expected'
 147
 148################################################################
 149
 150# tree has COPYING and rezrov.  work tree has the same COPYING and
 151# copy-edited COPYING.1, and unchanged rezrov.  We should not say
 152# anything about rezrov nor COPYING, since the revised again diff-raw
 153# nows how to say Copy.
 154
 155test_expect_success \
 156    'prepare work tree once again' \
 157    'cat ../../COPYING >COPYING &&
 158     git-update-cache --add --remove COPYING COPYING.1'
 159
 160git-diff-cache -C $tree >current
 161cat >expected <<\EOF
 162:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234  COPYING COPYING.1
 163EOF
 164
 165test_expect_success \
 166    'validate output from rename/copy detection (#3)' \
 167    'compare_diff_raw current expected'
 168
 169# make sure diff-helper can grok it.
 170mv expected diff-raw
 171GIT_DIFF_OPTS=--unified=0 git-diff-helper <diff-raw >current
 172cat >expected <<\EOF
 173diff --git a/COPYING b/COPYING.1
 174copy from COPYING
 175copy to COPYING.1
 176--- a/COPYING
 177+++ b/COPYING.1
 178@@ -6 +6 @@
 179- HOWEVER, in order to allow a migration to GPLv3 if that seems like
 180+ However, in order to allow a migration to GPLv3 if that seems like
 181EOF
 182
 183test_expect_success \
 184    'validate output from diff-helper (#3)' \
 185    'compare_diff_patch current expected'
 186
 187test_done