t / t4008-diff-break-rewrite.shon commit t6044: replace seq by test_seq (3f215b0)
   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.  The latter
  14two are then merged back into a single "complete rewrite".
  15
  16Further, with -B and -M together, these three modifications should
  17turn into rename-edit of file0 into file1.
  18
  19Starting from the same two files in the tree, we swap file0 and file1.
  20With -B, this should be detected as two complete rewrites.
  21
  22Further, with -B and -M together, these should turn into two renames.
  23'
  24. ./test-lib.sh
  25. "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
  26
  27test_expect_success setup '
  28        cat "$TEST_DIRECTORY"/diff-lib/README >file0 &&
  29        cat "$TEST_DIRECTORY"/diff-lib/COPYING >file1 &&
  30        git update-index --add file0 file1 &&
  31        git tag reference $(git write-tree)
  32'
  33
  34test_expect_success 'change file1 with copy-edit of file0 and remove file0' '
  35        sed -e "s/git/GIT/" file0 >file1 &&
  36        rm -f file0 &&
  37        git update-index --remove file0 file1
  38'
  39
  40test_expect_success 'run diff with -B (#1)' '
  41        git diff-index -B --cached reference >current &&
  42        cat >expect <<-\EOF &&
  43        :100644 000000 548142c327a6790ff8821d67c2ee1eff7a656b52 0000000000000000000000000000000000000000 D      file0
  44        :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec M100   file1
  45        EOF
  46        compare_diff_raw expect current
  47'
  48
  49test_expect_success 'run diff with -B and -M (#2)' '
  50        git diff-index -B -M reference >current &&
  51        cat >expect <<-\EOF &&
  52        :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec R100   file0   file1
  53        EOF
  54        compare_diff_raw expect current
  55'
  56
  57test_expect_success 'swap file0 and file1' '
  58        rm -f file0 file1 &&
  59        git read-tree -m reference &&
  60        git checkout-index -f -u -a &&
  61        mv file0 tmp &&
  62        mv file1 file0 &&
  63        mv tmp file1 &&
  64        git update-index file0 file1
  65'
  66
  67test_expect_success 'run diff with -B (#3)' '
  68        git diff-index -B reference >current &&
  69        cat >expect <<-\EOF &&
  70        :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 6ff87c4664981e4397625791c8ea3bbb5f2279a3 M100   file0
  71        :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M100   file1
  72        EOF
  73        compare_diff_raw expect current
  74'
  75
  76test_expect_success 'run diff with -B and -M (#4)' '
  77        git diff-index -B -M reference >current &&
  78        cat >expect <<-\EOF &&
  79        :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 R100   file1   file0
  80        :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 548142c327a6790ff8821d67c2ee1eff7a656b52 R100   file0   file1
  81        EOF
  82        compare_diff_raw expect current
  83'
  84
  85test_expect_success 'make file0 into something completely different' '
  86        rm -f file0 &&
  87        test_ln_s_add frotz file0 &&
  88        git update-index file1
  89'
  90
  91test_expect_success 'run diff with -B (#5)' '
  92        git diff-index -B reference >current &&
  93        cat >expect <<-\EOF &&
  94        :100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T      file0
  95        :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M100   file1
  96        EOF
  97        compare_diff_raw expect current
  98'
  99
 100test_expect_success 'run diff with -B -M (#6)' '
 101        git diff-index -B -M reference >current &&
 102
 103        # file0 changed from regular to symlink.  file1 is the same as the preimage
 104        # of file0.  Because the change does not make file0 disappear, file1 is
 105        # denoted as a copy of file0
 106        cat >expect <<-\EOF &&
 107        :100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T      file0
 108        :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 548142c327a6790ff8821d67c2ee1eff7a656b52 C      file0   file1
 109        EOF
 110        compare_diff_raw expect current
 111'
 112
 113test_expect_success 'run diff with -M (#7)' '
 114        git diff-index -M reference >current &&
 115
 116        # This should not mistake file0 as the copy source of new file1
 117        # due to type differences.
 118        cat >expect <<-\EOF &&
 119        :100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T      file0
 120        :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M      file1
 121        EOF
 122        compare_diff_raw expect current
 123'
 124
 125test_expect_success 'file1 edited to look like file0 and file0 rename-edited to file2' '
 126        rm -f file0 file1 &&
 127        git read-tree -m reference &&
 128        git checkout-index -f -u -a &&
 129        sed -e "s/git/GIT/" file0 >file1 &&
 130        sed -e "s/git/GET/" file0 >file2 &&
 131        rm -f file0 &&
 132        git update-index --add --remove file0 file1 file2
 133'
 134
 135test_expect_success 'run diff with -B (#8)' '
 136        git diff-index -B reference >current &&
 137        cat >expect <<-\EOF &&
 138        :100644 000000 548142c327a6790ff8821d67c2ee1eff7a656b52 0000000000000000000000000000000000000000 D      file0
 139        :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec M100   file1
 140        :000000 100644 0000000000000000000000000000000000000000 69a939f651686f56322566e2fd76715947a24162 A      file2
 141        EOF
 142        compare_diff_raw expect current
 143'
 144
 145test_expect_success 'run diff with -B -C (#9)' '
 146        git diff-index -B -C reference >current &&
 147        cat >expect <<-\EOF &&
 148        :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec C095   file0   file1
 149        :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 69a939f651686f56322566e2fd76715947a24162 R095   file0   file2
 150        EOF
 151        compare_diff_raw expect current
 152'
 153
 154test_done