Junio C Hamano | 1665217 | 2006-09-27 12:34:37 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Revision traversal vs grafts and path limiter' |
| 4 | |
Johannes Schindelin | 1550bb6 | 2020-11-18 23:44:36 +0000 | [diff] [blame] | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
Junio C Hamano | 1665217 | 2006-09-27 12:34:37 -0700 | [diff] [blame] | 8 | . ./test-lib.sh |
| 9 | |
| 10 | test_expect_success setup ' |
| 11 | mkdir subdir && |
| 12 | echo >fileA fileA && |
| 13 | echo >subdir/fileB fileB && |
| 14 | git add fileA subdir/fileB && |
| 15 | git commit -a -m "Initial in one history." && |
Elia Pinto | 11da571 | 2016-01-07 14:51:42 +0100 | [diff] [blame] | 16 | A0=$(git rev-parse --verify HEAD) && |
Junio C Hamano | 1665217 | 2006-09-27 12:34:37 -0700 | [diff] [blame] | 17 | |
| 18 | echo >fileA fileA modified && |
| 19 | git commit -a -m "Second in one history." && |
Elia Pinto | 11da571 | 2016-01-07 14:51:42 +0100 | [diff] [blame] | 20 | A1=$(git rev-parse --verify HEAD) && |
Junio C Hamano | 1665217 | 2006-09-27 12:34:37 -0700 | [diff] [blame] | 21 | |
| 22 | echo >subdir/fileB fileB modified && |
| 23 | git commit -a -m "Third in one history." && |
Elia Pinto | 11da571 | 2016-01-07 14:51:42 +0100 | [diff] [blame] | 24 | A2=$(git rev-parse --verify HEAD) && |
Junio C Hamano | 1665217 | 2006-09-27 12:34:37 -0700 | [diff] [blame] | 25 | |
Han-Wen Nienhuys | 977f8ac | 2021-08-02 16:53:36 +0000 | [diff] [blame] | 26 | git update-ref -d refs/heads/main && |
| 27 | rm -f .git/index && |
Junio C Hamano | 1665217 | 2006-09-27 12:34:37 -0700 | [diff] [blame] | 28 | |
| 29 | echo >fileA fileA again && |
| 30 | echo >subdir/fileB fileB again && |
| 31 | git add fileA subdir/fileB && |
| 32 | git commit -a -m "Initial in alternate history." && |
Elia Pinto | 11da571 | 2016-01-07 14:51:42 +0100 | [diff] [blame] | 33 | B0=$(git rev-parse --verify HEAD) && |
Junio C Hamano | 1665217 | 2006-09-27 12:34:37 -0700 | [diff] [blame] | 34 | |
| 35 | echo >fileA fileA modified in alternate history && |
| 36 | git commit -a -m "Second in alternate history." && |
Elia Pinto | 11da571 | 2016-01-07 14:51:42 +0100 | [diff] [blame] | 37 | B1=$(git rev-parse --verify HEAD) && |
Junio C Hamano | 1665217 | 2006-09-27 12:34:37 -0700 | [diff] [blame] | 38 | |
| 39 | echo >subdir/fileB fileB modified in alternate history && |
| 40 | git commit -a -m "Third in alternate history." && |
Elia Pinto | 11da571 | 2016-01-07 14:51:42 +0100 | [diff] [blame] | 41 | B2=$(git rev-parse --verify HEAD) && |
Junio C Hamano | 1665217 | 2006-09-27 12:34:37 -0700 | [diff] [blame] | 42 | : done |
| 43 | ' |
| 44 | |
| 45 | check () { |
| 46 | type=$1 |
| 47 | shift |
| 48 | |
| 49 | arg= |
| 50 | which=arg |
| 51 | rm -f test.expect |
| 52 | for a |
| 53 | do |
| 54 | if test "z$a" = z-- |
| 55 | then |
| 56 | which=expect |
| 57 | child= |
| 58 | continue |
| 59 | fi |
| 60 | if test "$which" = arg |
| 61 | then |
| 62 | arg="$arg$a " |
| 63 | continue |
| 64 | fi |
| 65 | if test "$type" = basic |
| 66 | then |
| 67 | echo "$a" |
| 68 | else |
| 69 | if test "z$child" != z |
| 70 | then |
| 71 | echo "$child $a" |
| 72 | fi |
| 73 | child="$a" |
| 74 | fi |
| 75 | done >test.expect |
| 76 | if test "$type" != basic && test "z$child" != z |
| 77 | then |
| 78 | echo >>test.expect $child |
| 79 | fi |
| 80 | if test $type = basic |
| 81 | then |
| 82 | git rev-list $arg >test.actual |
| 83 | elif test $type = parents |
| 84 | then |
| 85 | git rev-list --parents $arg >test.actual |
| 86 | elif test $type = parents-raw |
| 87 | then |
| 88 | git rev-list --parents --pretty=raw $arg | |
| 89 | sed -n -e 's/^commit //p' >test.actual |
| 90 | fi |
Gary V. Vaughan | 4fdf71b | 2010-05-14 09:31:37 +0000 | [diff] [blame] | 91 | test_cmp test.expect test.actual |
Junio C Hamano | 1665217 | 2006-09-27 12:34:37 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | for type in basic parents parents-raw |
| 95 | do |
| 96 | test_expect_success 'without grafts' " |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 97 | rm -f .git/info/grafts && |
Junio C Hamano | 1665217 | 2006-09-27 12:34:37 -0700 | [diff] [blame] | 98 | check $type $B2 -- $B2 $B1 $B0 |
| 99 | " |
| 100 | |
| 101 | test_expect_success 'with grafts' " |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 102 | echo '$B0 $A2' >.git/info/grafts && |
Junio C Hamano | 1665217 | 2006-09-27 12:34:37 -0700 | [diff] [blame] | 103 | check $type $B2 -- $B2 $B1 $B0 $A2 $A1 $A0 |
| 104 | " |
| 105 | |
| 106 | test_expect_success 'without grafts, with pathlimit' " |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 107 | rm -f .git/info/grafts && |
Junio C Hamano | 1665217 | 2006-09-27 12:34:37 -0700 | [diff] [blame] | 108 | check $type $B2 subdir -- $B2 $B0 |
| 109 | " |
| 110 | |
| 111 | test_expect_success 'with grafts, with pathlimit' " |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 112 | echo '$B0 $A2' >.git/info/grafts && |
Junio C Hamano | 1665217 | 2006-09-27 12:34:37 -0700 | [diff] [blame] | 113 | check $type $B2 subdir -- $B2 $B0 $A2 $A0 |
| 114 | " |
| 115 | |
| 116 | done |
Johannes Schindelin | f9f99b3 | 2018-04-29 00:44:44 +0200 | [diff] [blame] | 117 | |
| 118 | test_expect_success 'show advice that grafts are deprecated' ' |
| 119 | git show HEAD 2>err && |
| 120 | test_i18ngrep "git replace" err && |
| 121 | test_config advice.graftFileDeprecated false && |
| 122 | git show HEAD 2>err && |
| 123 | test_i18ngrep ! "git replace" err |
| 124 | ' |
| 125 | |
Junio C Hamano | 1665217 | 2006-09-27 12:34:37 -0700 | [diff] [blame] | 126 | test_done |