blob: d93458377690cdddddf73621f24d7782de959aec [file] [log] [blame]
Ramsay Jones00f66f02010-12-21 18:50:47 +00001#!/bin/sh
Clemens Buchacherbeb17212010-09-19 11:59:27 +02002
3test_description='git rebase - test patch id computation'
4
5. ./test-lib.sh
6
Junio C Hamanob687cd62014-06-09 14:03:10 -07007count () {
Clemens Buchacherbeb17212010-09-19 11:59:27 +02008 i=0
9 while test $i -lt $1
10 do
11 echo "$i"
12 i=$(($i+1))
13 done
14}
15
Junio C Hamanob687cd62014-06-09 14:03:10 -070016scramble () {
Clemens Buchacherbeb17212010-09-19 11:59:27 +020017 i=0
18 while read x
19 do
20 if test $i -ne 0
21 then
22 echo "$x"
23 fi
Ramsay Jones00f66f02010-12-21 18:50:47 +000024 i=$((($i+1) % 10))
Junio C Hamanob687cd62014-06-09 14:03:10 -070025 done <"$1" >"$1.new"
Clemens Buchacherbeb17212010-09-19 11:59:27 +020026 mv -f "$1.new" "$1"
27}
28
Junio C Hamanob687cd62014-06-09 14:03:10 -070029run () {
Clemens Buchacherbeb17212010-09-19 11:59:27 +020030 echo \$ "$@"
31 /usr/bin/time "$@" >/dev/null
32}
33
34test_expect_success 'setup' '
Ramkumar Ramachandra02380382011-12-08 18:40:17 +053035 git commit --allow-empty -m initial &&
Clemens Buchacherbeb17212010-09-19 11:59:27 +020036 git tag root
37'
38
Junio C Hamanob687cd62014-06-09 14:03:10 -070039do_tests () {
40 nlines=$1 pr=${2-}
Clemens Buchacherbeb17212010-09-19 11:59:27 +020041
42 test_expect_success $pr "setup: $nlines lines" "
43 rm -f .gitattributes &&
44 git checkout -q -f master &&
45 git reset --hard root &&
46 count $nlines >file &&
47 git add file &&
48 git commit -q -m initial &&
49 git branch -f other &&
50
51 scramble file &&
52 git add file &&
53 git commit -q -m 'change big file' &&
54
55 git checkout -q other &&
56 : >newfile &&
57 git add newfile &&
58 git commit -q -m 'add small file' &&
59
60 git cherry-pick master >/dev/null 2>&1
61 "
62
63 test_debug "
64 run git diff master^\!
65 "
66
67 test_expect_success $pr 'setup attributes' "
68 echo 'file binary' >.gitattributes
69 "
70
71 test_debug "
72 run git format-patch --stdout master &&
73 run git format-patch --stdout --ignore-if-in-upstream master
74 "
75
Jeff King577dfd02016-05-13 16:47:18 -040076 test_expect_success $pr 'detect upstream patch' '
Clemens Buchacherbeb17212010-09-19 11:59:27 +020077 git checkout -q master &&
78 scramble file &&
79 git add file &&
Jeff King577dfd02016-05-13 16:47:18 -040080 git commit -q -m "change big file again" &&
Clemens Buchacherbeb17212010-09-19 11:59:27 +020081 git checkout -q other^{} &&
82 git rebase master &&
Denton Liu1c9fd322020-01-06 23:53:09 -050083 git rev-list master...HEAD~ >revs &&
84 test_must_be_empty revs
Jeff King577dfd02016-05-13 16:47:18 -040085 '
Clemens Buchacherbeb17212010-09-19 11:59:27 +020086
Jeff King577dfd02016-05-13 16:47:18 -040087 test_expect_success $pr 'do not drop patch' '
Clemens Buchacherbeb17212010-09-19 11:59:27 +020088 git branch -f squashed master &&
89 git checkout -q -f squashed &&
90 git reset -q --soft HEAD~2 &&
91 git commit -q -m squashed &&
92 git checkout -q other^{} &&
93 test_must_fail git rebase squashed &&
brian m. carlson2da1b052020-03-20 21:52:41 +000094 git rebase --quit
Jeff King577dfd02016-05-13 16:47:18 -040095 '
Clemens Buchacherbeb17212010-09-19 11:59:27 +020096}
97
Junio C Hamanob687cd62014-06-09 14:03:10 -070098do_tests 500
99do_tests 50000 EXPENSIVE
Clemens Buchacherbeb17212010-09-19 11:59:27 +0200100
101test_done