t / t4008-diff-break-rewrite.shon commit git-read-tree: simplify merge loops enormously (d723c69)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5
   6test_description='Break and then rename
   7
   8We have two very different files, file0 and file1, registered in a tree.
   9
  10We update file1 so drastically that it is more similar to file0, and
  11then remove file0.  With -B, changes to file1 should be broken into
  12separate delete and create, resulting in removal of file0, removal of
  13original file1 and creation of completely rewritten file1.
  14
  15Further, with -B and -M together, these three modifications should
  16turn into rename-edit of file0 into file1.
  17
  18Starting from the same two files in the tree, we swap file0 and file1.
  19With -B, this should be detected as two complete rewrites, resulting in
  20four changes in total.
  21
  22Further, with -B and -M together, these should turn into two renames.
  23'
  24. ./test-lib.sh
  25. ../diff-lib.sh ;# test-lib chdir's into trash
  26
  27test_expect_success \
  28    setup \
  29    'cat ../../README >file0 &&
  30     cat ../../COPYING >file1 &&
  31    git-update-cache --add file0 file1 &&
  32    tree=$(git-write-tree) &&
  33    echo "$tree"'
  34
  35test_expect_success \
  36    'change file1 with copy-edit of file0 and remove file0' \
  37    'sed -e "s/git/GIT/" file0 >file1 &&
  38     rm -f file0 &&
  39    git-update-cache --remove file0 file1'
  40
  41test_expect_success \
  42    'run diff with -B' \
  43    'git-diff-cache -B --cached "$tree" >current'
  44
  45cat >expected <<\EOF
  46:100644 000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 0000000000000000000000000000000000000000 D      file0
  47:100644 000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0000000000000000000000000000000000000000 D100   file1
  48:000000 100644 0000000000000000000000000000000000000000 11e331465a89c394dc25c780de230043750c1ec8 N100   file1
  49EOF
  50
  51test_expect_success \
  52    'validate result of -B (#1)' \
  53    'compare_diff_raw current expected'
  54
  55test_expect_success \
  56    'run diff with -B and -M' \
  57    'git-diff-cache -B -M "$tree" >current'
  58
  59cat >expected <<\EOF
  60:100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 08bb2fb671deff4c03a4d4a0a1315dff98d5732c R100   file0   file1
  61EOF
  62
  63test_expect_success \
  64    'validate result of -B -M (#2)' \
  65    'compare_diff_raw current expected'
  66
  67test_expect_success \
  68    'swap file0 and file1' \
  69    'rm -f file0 file1 &&
  70     git-read-tree -m $tree &&
  71     git-checkout-cache -f -u -a &&
  72     mv file0 tmp &&
  73     mv file1 file0 &&
  74     mv tmp file1 &&
  75     git-update-cache file0 file1'
  76
  77test_expect_success \
  78    'run diff with -B' \
  79    'git-diff-cache -B "$tree" >current'
  80
  81cat >expected <<\EOF
  82:100644 000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 0000000000000000000000000000000000000000 D100   file0
  83:000000 100644 0000000000000000000000000000000000000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 N100   file0
  84:100644 000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0000000000000000000000000000000000000000 D100   file1
  85:000000 100644 0000000000000000000000000000000000000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 N100   file1
  86EOF
  87
  88test_expect_success \
  89    'validate result of -B (#3)' \
  90    'compare_diff_raw current expected'
  91
  92test_expect_success \
  93    'run diff with -B and -M' \
  94    'git-diff-cache -B -M "$tree" >current'
  95
  96cat >expected <<\EOF
  97:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 R100   file1   file0
  98:100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 R100   file0   file1
  99EOF
 100
 101test_expect_success \
 102    'validate result of -B -M (#4)' \
 103    'compare_diff_raw current expected'
 104
 105test_expect_success \
 106    'make file0 into something completely different' \
 107    'rm -f file0 &&
 108     ln -s frotz file0 &&
 109     git-update-cache file0 file1'
 110
 111test_expect_success \
 112    'run diff with -B' \
 113    'git-diff-cache -B "$tree" >current'
 114
 115cat >expected <<\EOF
 116:100644 120000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 67be421f88824578857624f7b3dc75e99a8a1481 T      file0
 117:100644 000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0000000000000000000000000000000000000000 D100   file1
 118:000000 100644 0000000000000000000000000000000000000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 N100   file1
 119EOF
 120
 121test_expect_success \
 122    'validate result of -B (#5)' \
 123    'compare_diff_raw current expected'
 124
 125test_expect_success \
 126    'run diff with -B' \
 127    'git-diff-cache -B -M "$tree" >current'
 128
 129# This should not mistake file0 as the copy source of new file1
 130# due to type differences.
 131cat >expected <<\EOF
 132:100644 120000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 67be421f88824578857624f7b3dc75e99a8a1481 T      file0
 133:100644 000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0000000000000000000000000000000000000000 D100   file1
 134:000000 100644 0000000000000000000000000000000000000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 N100   file1
 135EOF
 136
 137test_expect_success \
 138    'validate result of -B -M (#6)' \
 139    'compare_diff_raw current expected'
 140
 141test_expect_success \
 142    'run diff with -M' \
 143    'git-diff-cache -M "$tree" >current'
 144
 145# This should not mistake file0 as the copy source of new file1
 146# due to type differences.
 147cat >expected <<\EOF
 148:100644 120000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 67be421f88824578857624f7b3dc75e99a8a1481 T      file0
 149:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M      file1
 150EOF
 151
 152test_expect_success \
 153    'validate result of -M (#7)' \
 154    'compare_diff_raw current expected'
 155
 156test_expect_success \
 157    'file1 edited to look like file0 and file0 rename-edited to file2' \
 158    'rm -f file0 file1 &&
 159     git-read-tree -m $tree &&
 160     git-checkout-cache -f -u -a &&
 161     sed -e "s/git/GIT/" file0 >file1 &&
 162     sed -e "s/git/GET/" file0 >file2 &&
 163     rm -f file0
 164     git-update-cache --add --remove file0 file1 file2'
 165
 166test_expect_success \
 167    'run diff with -B' \
 168    'git-diff-cache -B "$tree" >current'
 169
 170cat >expected <<\EOF
 171:100644 000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 0000000000000000000000000000000000000000 D      file0
 172:100644 000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0000000000000000000000000000000000000000 D100   file1
 173:000000 100644 0000000000000000000000000000000000000000 08bb2fb671deff4c03a4d4a0a1315dff98d5732c N100   file1
 174:000000 100644 0000000000000000000000000000000000000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 N      file2
 175EOF
 176
 177test_expect_success \
 178    'validate result of -B (#8)' \
 179    'compare_diff_raw current expected'
 180
 181test_expect_success \
 182    'run diff with -B -M' \
 183    'git-diff-cache -B -M "$tree" >current'
 184
 185cat >expected <<\EOF
 186:100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 08bb2fb671deff4c03a4d4a0a1315dff98d5732c C095   file0   file1
 187:100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 59f832e5c8b3f7e486be15ad0cd3e95ba9af8998 R095   file0   file2
 188EOF
 189
 190test_expect_success \
 191    'validate result of -B -M (#9)' \
 192    'compare_diff_raw current expected'
 193
 194test_done