08e30b30f40e767c19f3b074a19840f07944d063
   1#!/bin/sh
   2
   3test_description='git rebase - test patch id computation'
   4
   5. ./test-lib.sh
   6
   7test_set_prereq NOT_EXPENSIVE
   8test -n "$GIT_PATCHID_TIMING_TESTS" && test_set_prereq EXPENSIVE
   9
  10count()
  11{
  12        i=0
  13        while test $i -lt $1
  14        do
  15                echo "$i"
  16                i=$(($i+1))
  17        done
  18}
  19
  20scramble()
  21{
  22        i=0
  23        while read x
  24        do
  25                if test $i -ne 0
  26                then
  27                        echo "$x"
  28                fi
  29                i=$((($i+1) % 10))
  30        done < "$1" > "$1.new"
  31        mv -f "$1.new" "$1"
  32}
  33
  34run()
  35{
  36        echo \$ "$@"
  37        /usr/bin/time "$@" >/dev/null
  38}
  39
  40test_expect_success 'setup' '
  41        git commit --allow-empty -m initial &&
  42        git tag root
  43'
  44
  45do_tests()
  46{
  47        pr=$1
  48        nlines=$2
  49
  50        test_expect_success $pr "setup: $nlines lines" "
  51                rm -f .gitattributes &&
  52                git checkout -q -f master &&
  53                git reset --hard root &&
  54                count $nlines >file &&
  55                git add file &&
  56                git commit -q -m initial &&
  57                git branch -f other &&
  58
  59                scramble file &&
  60                git add file &&
  61                git commit -q -m 'change big file' &&
  62
  63                git checkout -q other &&
  64                : >newfile &&
  65                git add newfile &&
  66                git commit -q -m 'add small file' &&
  67
  68                git cherry-pick master >/dev/null 2>&1
  69        "
  70
  71        test_debug "
  72                run git diff master^\!
  73        "
  74
  75        test_expect_success $pr 'setup attributes' "
  76                echo 'file binary' >.gitattributes
  77        "
  78
  79        test_debug "
  80                run git format-patch --stdout master &&
  81                run git format-patch --stdout --ignore-if-in-upstream master
  82        "
  83
  84        test_expect_success $pr 'detect upstream patch' "
  85                git checkout -q master &&
  86                scramble file &&
  87                git add file &&
  88                git commit -q -m 'change big file again' &&
  89                git checkout -q other^{} &&
  90                git rebase master &&
  91                test_must_fail test -n \"\$(git rev-list master...HEAD~)\"
  92        "
  93
  94        test_expect_success $pr 'do not drop patch' "
  95                git branch -f squashed master &&
  96                git checkout -q -f squashed &&
  97                git reset -q --soft HEAD~2 &&
  98                git commit -q -m squashed &&
  99                git checkout -q other^{} &&
 100                test_must_fail git rebase squashed &&
 101                rm -rf .git/rebase-apply
 102        "
 103}
 104
 105do_tests NOT_EXPENSIVE 500
 106do_tests EXPENSIVE 50000
 107
 108test_done