t / t4104-apply-boundary.shon commit t4126: fix test that happened to work due to timing (d88593f)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5
   6test_description='git apply boundary tests
   7
   8'
   9. ./test-lib.sh
  10
  11L="c d e f g h i j k l m n o p q r s t u v w x"
  12
  13test_expect_success setup '
  14        for i in b '"$L"' y
  15        do
  16                echo $i
  17        done >victim &&
  18        cat victim >original &&
  19        git update-index --add victim &&
  20
  21        : add to the head
  22        for i in a b '"$L"' y
  23        do
  24                echo $i
  25        done >victim &&
  26        cat victim >add-a-expect &&
  27        git diff victim >add-a-patch.with &&
  28        git diff --unified=0 >add-a-patch.without &&
  29
  30        : modify at the head
  31        for i in a '"$L"' y
  32        do
  33                echo $i
  34        done >victim &&
  35        cat victim >mod-a-expect &&
  36        git diff victim >mod-a-patch.with &&
  37        git diff --unified=0 >mod-a-patch.without &&
  38
  39        : remove from the head
  40        for i in '"$L"' y
  41        do
  42                echo $i
  43        done >victim &&
  44        cat victim >del-a-expect &&
  45        git diff victim >del-a-patch.with
  46        git diff --unified=0 >del-a-patch.without &&
  47
  48        : add to the tail
  49        for i in b '"$L"' y z
  50        do
  51                echo $i
  52        done >victim &&
  53        cat victim >add-z-expect &&
  54        git diff victim >add-z-patch.with &&
  55        git diff --unified=0 >add-z-patch.without &&
  56
  57        : modify at the tail
  58        for i in a '"$L"' y
  59        do
  60                echo $i
  61        done >victim &&
  62        cat victim >mod-z-expect &&
  63        git diff victim >mod-z-patch.with &&
  64        git diff --unified=0 >mod-z-patch.without &&
  65
  66        : remove from the tail
  67        for i in b '"$L"'
  68        do
  69                echo $i
  70        done >victim &&
  71        cat victim >del-z-expect &&
  72        git diff victim >del-z-patch.with
  73        git diff --unified=0 >del-z-patch.without &&
  74
  75        : done
  76'
  77
  78for with in with without
  79do
  80        case "$with" in
  81        with) u= ;;
  82        without) u='--unidiff-zero ' ;;
  83        esac
  84        for kind in add-a add-z mod-a mod-z del-a del-z
  85        do
  86                test_expect_success "apply $kind-patch $with context" '
  87                        cat original >victim &&
  88                        git update-index victim &&
  89                        git apply --index '"$u$kind-patch.$with"' || {
  90                                cat '"$kind-patch.$with"'
  91                                (exit 1)
  92                        } &&
  93                        test_cmp '"$kind"'-expect victim
  94                '
  95        done
  96done
  97
  98for kind in add-a add-z mod-a mod-z del-a del-z
  99do
 100        rm -f $kind-ng.without
 101        sed     -e "s/^diff --git /diff /" \
 102                -e '/^index /d' \
 103                <$kind-patch.without >$kind-ng.without
 104        test_expect_success "apply non-git $kind-patch without context" '
 105                cat original >victim &&
 106                git update-index victim &&
 107                git apply --unidiff-zero --index '"$kind-ng.without"' || {
 108                        cat '"$kind-ng.without"'
 109                        (exit 1)
 110                } &&
 111                test_cmp '"$kind"'-expect victim
 112        '
 113done
 114
 115test_expect_success 'two lines' '
 116
 117        >file &&
 118        git add file &&
 119        echo aaa >file &&
 120        git diff >patch &&
 121        git add file &&
 122        echo bbb >file &&
 123        git add file &&
 124        test_must_fail git apply --check patch
 125
 126'
 127
 128test_done