t / t4127-apply-same-fn.shon commit git svn: migrate tests to use lib-httpd (a8a5d25)
   1#!/bin/sh
   2
   3test_description='apply same filename'
   4
   5. ./test-lib.sh
   6
   7modify () {
   8        sed -e "$1" < "$2" > "$2".x &&
   9        mv "$2".x "$2"
  10}
  11
  12test_expect_success setup '
  13        for i in a b c d e f g h i j k l m
  14        do
  15                echo $i
  16        done >same_fn &&
  17        cp same_fn other_fn &&
  18        git add same_fn other_fn &&
  19        git commit -m initial
  20'
  21test_expect_success 'apply same filename with independent changes' '
  22        modify "s/^d/z/" same_fn &&
  23        git diff > patch0 &&
  24        git add same_fn &&
  25        modify "s/^i/y/" same_fn &&
  26        git diff >> patch0 &&
  27        cp same_fn same_fn2 &&
  28        git reset --hard &&
  29        git apply patch0 &&
  30        test_cmp same_fn same_fn2
  31'
  32
  33test_expect_success 'apply same filename with overlapping changes' '
  34        git reset --hard &&
  35        modify "s/^d/z/" same_fn &&
  36        git diff > patch0 &&
  37        git add same_fn &&
  38        modify "s/^e/y/" same_fn &&
  39        git diff >> patch0 &&
  40        cp same_fn same_fn2 &&
  41        git reset --hard &&
  42        git apply patch0 &&
  43        test_cmp same_fn same_fn2
  44'
  45
  46test_expect_success 'apply same new filename after rename' '
  47        git reset --hard &&
  48        git mv same_fn new_fn &&
  49        modify "s/^d/z/" new_fn &&
  50        git add new_fn &&
  51        git diff -M --cached > patch1 &&
  52        modify "s/^e/y/" new_fn &&
  53        git diff >> patch1 &&
  54        cp new_fn new_fn2 &&
  55        git reset --hard &&
  56        git apply --index patch1 &&
  57        test_cmp new_fn new_fn2
  58'
  59
  60test_expect_success 'apply same old filename after rename -- should fail.' '
  61        git reset --hard &&
  62        git mv same_fn new_fn &&
  63        modify "s/^d/z/" new_fn &&
  64        git add new_fn &&
  65        git diff -M --cached > patch1 &&
  66        git mv new_fn same_fn &&
  67        modify "s/^e/y/" same_fn &&
  68        git diff >> patch1 &&
  69        git reset --hard &&
  70        test_must_fail git apply patch1
  71'
  72
  73test_expect_success 'apply A->B (rename), C->A (rename), A->A -- should pass.' '
  74        git reset --hard &&
  75        git mv same_fn new_fn &&
  76        modify "s/^d/z/" new_fn &&
  77        git add new_fn &&
  78        git diff -M --cached > patch1 &&
  79        git commit -m "a rename" &&
  80        git mv other_fn same_fn &&
  81        modify "s/^e/y/" same_fn &&
  82        git add same_fn &&
  83        git diff -M --cached >> patch1 &&
  84        modify "s/^g/x/" same_fn &&
  85        git diff >> patch1 &&
  86        git reset --hard HEAD^ &&
  87        git apply patch1
  88'
  89
  90test_done