Junio C Hamano | 991c3dc | 2008-02-02 23:47:22 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Michael J Gruber | 6a6ebde | 2011-03-23 10:38:51 +0100 | [diff] [blame] | 3 | test_description='ancestor culling and limiting by parent number' |
Junio C Hamano | 991c3dc | 2008-02-02 23:47:22 -0800 | [diff] [blame] | 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 | 991c3dc | 2008-02-02 23:47:22 -0800 | [diff] [blame] | 8 | . ./test-lib.sh |
| 9 | |
Michael J Gruber | 6a6ebde | 2011-03-23 10:38:51 +0100 | [diff] [blame] | 10 | check_revlist () { |
| 11 | rev_list_args="$1" && |
| 12 | shift && |
| 13 | git rev-parse "$@" >expect && |
| 14 | git rev-list $rev_list_args --all >actual && |
| 15 | test_cmp expect actual |
| 16 | } |
| 17 | |
Junio C Hamano | 991c3dc | 2008-02-02 23:47:22 -0800 | [diff] [blame] | 18 | test_expect_success setup ' |
| 19 | |
| 20 | touch file && |
| 21 | git add file && |
| 22 | |
Michael J Gruber | 8ee5059 | 2011-03-21 11:14:05 +0100 | [diff] [blame] | 23 | test_commit one && |
Junio C Hamano | 991c3dc | 2008-02-02 23:47:22 -0800 | [diff] [blame] | 24 | |
Jonathan Nieder | a48fcd8 | 2010-10-30 20:46:54 -0500 | [diff] [blame] | 25 | test_tick=$(($test_tick - 2400)) && |
Junio C Hamano | 991c3dc | 2008-02-02 23:47:22 -0800 | [diff] [blame] | 26 | |
Michael J Gruber | 8ee5059 | 2011-03-21 11:14:05 +0100 | [diff] [blame] | 27 | test_commit two && |
| 28 | test_commit three && |
| 29 | test_commit four && |
Junio C Hamano | 991c3dc | 2008-02-02 23:47:22 -0800 | [diff] [blame] | 30 | |
| 31 | git log --pretty=oneline --abbrev-commit |
| 32 | ' |
| 33 | |
Linus Torvalds | 7d00419 | 2008-03-17 18:56:33 -0700 | [diff] [blame] | 34 | test_expect_success 'one is ancestor of others and should not be shown' ' |
Junio C Hamano | 991c3dc | 2008-02-02 23:47:22 -0800 | [diff] [blame] | 35 | |
| 36 | git rev-list one --not four >result && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 37 | test_must_be_empty result |
Junio C Hamano | 991c3dc | 2008-02-02 23:47:22 -0800 | [diff] [blame] | 38 | |
| 39 | ' |
| 40 | |
Michael J Gruber | 6a6ebde | 2011-03-23 10:38:51 +0100 | [diff] [blame] | 41 | test_expect_success 'setup roots, merges and octopuses' ' |
| 42 | |
| 43 | git checkout --orphan newroot && |
| 44 | test_commit five && |
| 45 | git checkout -b sidebranch two && |
| 46 | test_commit six && |
| 47 | git checkout -b anotherbranch three && |
| 48 | test_commit seven && |
| 49 | git checkout -b yetanotherbranch four && |
| 50 | test_commit eight && |
Johannes Schindelin | 1550bb6 | 2020-11-18 23:44:36 +0000 | [diff] [blame] | 51 | git checkout main && |
Junio C Hamano | e379fdf | 2016-03-18 13:21:09 -0700 | [diff] [blame] | 52 | test_tick && |
| 53 | git merge --allow-unrelated-histories -m normalmerge newroot && |
| 54 | git tag normalmerge && |
Michael J Gruber | 6a6ebde | 2011-03-23 10:38:51 +0100 | [diff] [blame] | 55 | test_tick && |
| 56 | git merge -m tripus sidebranch anotherbranch && |
| 57 | git tag tripus && |
| 58 | git checkout -b tetrabranch normalmerge && |
| 59 | test_tick && |
| 60 | git merge -m tetrapus sidebranch anotherbranch yetanotherbranch && |
| 61 | git tag tetrapus && |
Johannes Schindelin | 1550bb6 | 2020-11-18 23:44:36 +0000 | [diff] [blame] | 62 | git checkout main |
Michael J Gruber | 6a6ebde | 2011-03-23 10:38:51 +0100 | [diff] [blame] | 63 | ' |
| 64 | |
| 65 | test_expect_success 'rev-list roots' ' |
| 66 | |
| 67 | check_revlist "--max-parents=0" one five |
| 68 | ' |
| 69 | |
| 70 | test_expect_success 'rev-list no merges' ' |
| 71 | |
| 72 | check_revlist "--max-parents=1" one eight seven six five four three two && |
| 73 | check_revlist "--no-merges" one eight seven six five four three two |
| 74 | ' |
| 75 | |
| 76 | test_expect_success 'rev-list no octopuses' ' |
| 77 | |
| 78 | check_revlist "--max-parents=2" one normalmerge eight seven six five four three two |
| 79 | ' |
| 80 | |
| 81 | test_expect_success 'rev-list no roots' ' |
| 82 | |
| 83 | check_revlist "--min-parents=1" tetrapus tripus normalmerge eight seven six four three two |
| 84 | ' |
| 85 | |
| 86 | test_expect_success 'rev-list merges' ' |
| 87 | |
| 88 | check_revlist "--min-parents=2" tetrapus tripus normalmerge && |
| 89 | check_revlist "--merges" tetrapus tripus normalmerge |
| 90 | ' |
| 91 | |
| 92 | test_expect_success 'rev-list octopus' ' |
| 93 | |
| 94 | check_revlist "--min-parents=3" tetrapus tripus |
| 95 | ' |
| 96 | |
| 97 | test_expect_success 'rev-list ordinary commits' ' |
| 98 | |
| 99 | check_revlist "--min-parents=1 --max-parents=1" eight seven six four three two |
| 100 | ' |
| 101 | |
| 102 | test_expect_success 'rev-list --merges --no-merges yields empty set' ' |
| 103 | |
| 104 | check_revlist "--min-parents=2 --no-merges" && |
| 105 | check_revlist "--merges --no-merges" && |
| 106 | check_revlist "--no-merges --merges" |
| 107 | ' |
| 108 | |
| 109 | test_expect_success 'rev-list override and infinities' ' |
| 110 | |
| 111 | check_revlist "--min-parents=2 --max-parents=1 --max-parents=3" tripus normalmerge && |
| 112 | check_revlist "--min-parents=1 --min-parents=2 --max-parents=7" tetrapus tripus normalmerge && |
| 113 | check_revlist "--min-parents=2 --max-parents=8" tetrapus tripus normalmerge && |
| 114 | check_revlist "--min-parents=2 --max-parents=-1" tetrapus tripus normalmerge && |
| 115 | check_revlist "--min-parents=2 --no-max-parents" tetrapus tripus normalmerge && |
| 116 | check_revlist "--max-parents=0 --min-parents=1 --no-min-parents" one five |
| 117 | ' |
| 118 | |
Jonathan Nieder | 482ce70 | 2011-03-24 03:21:24 -0500 | [diff] [blame] | 119 | test_expect_success 'dodecapus' ' |
Michael J Gruber | 6a6ebde | 2011-03-23 10:38:51 +0100 | [diff] [blame] | 120 | |
Jonathan Nieder | 482ce70 | 2011-03-24 03:21:24 -0500 | [diff] [blame] | 121 | roots= && |
Michael J Gruber | 6a6ebde | 2011-03-23 10:38:51 +0100 | [diff] [blame] | 122 | for i in 1 2 3 4 5 6 7 8 9 10 11 |
| 123 | do |
Jonathan Nieder | 482ce70 | 2011-03-24 03:21:24 -0500 | [diff] [blame] | 124 | git checkout -b root$i five && |
| 125 | test_commit $i && |
| 126 | roots="$roots root$i" || |
| 127 | return |
Michael J Gruber | 6a6ebde | 2011-03-23 10:38:51 +0100 | [diff] [blame] | 128 | done && |
Johannes Schindelin | 1550bb6 | 2020-11-18 23:44:36 +0000 | [diff] [blame] | 129 | git checkout main && |
Michael J Gruber | 6a6ebde | 2011-03-23 10:38:51 +0100 | [diff] [blame] | 130 | test_tick && |
Jonathan Nieder | 482ce70 | 2011-03-24 03:21:24 -0500 | [diff] [blame] | 131 | git merge -m dodecapus $roots && |
| 132 | git tag dodecapus && |
Michael J Gruber | 6a6ebde | 2011-03-23 10:38:51 +0100 | [diff] [blame] | 133 | |
| 134 | check_revlist "--min-parents=4" dodecapus tetrapus && |
| 135 | check_revlist "--min-parents=8" dodecapus && |
| 136 | check_revlist "--min-parents=12" dodecapus && |
| 137 | check_revlist "--min-parents=13" && |
| 138 | check_revlist "--min-parents=4 --max-parents=11" tetrapus |
| 139 | ' |
Kacper Kornet | c19d1b4 | 2013-03-22 19:38:19 +0100 | [diff] [blame] | 140 | |
| 141 | test_expect_success 'ancestors with the same commit time' ' |
| 142 | |
| 143 | test_tick_keep=$test_tick && |
| 144 | for i in 1 2 3 4 5 6 7 8; do |
| 145 | test_tick=$test_tick_keep |
| 146 | test_commit t$i |
| 147 | done && |
| 148 | git rev-list t1^! --not t$i >result && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 149 | test_must_be_empty result |
Kacper Kornet | c19d1b4 | 2013-03-22 19:38:19 +0100 | [diff] [blame] | 150 | ' |
| 151 | |
Junio C Hamano | 991c3dc | 2008-02-02 23:47:22 -0800 | [diff] [blame] | 152 | test_done |