1#!/bin/sh
   2test_description='ancestor culling and limiting by parent number'
   4. ./test-lib.sh
   6check_revlist () {
   8        rev_list_args="$1" &&
   9        shift &&
  10        git rev-parse "$@" >expect &&
  11        git rev-list $rev_list_args --all >actual &&
  12        test_cmp expect actual
  13}
  14test_expect_success setup '
  16        touch file &&
  18        git add file &&
  19        test_commit one &&
  21        test_tick=$(($test_tick - 2400)) &&
  23        test_commit two &&
  25        test_commit three &&
  26        test_commit four &&
  27        git log --pretty=oneline --abbrev-commit
  29'
  30test_expect_success 'one is ancestor of others and should not be shown' '
  32        git rev-list one --not four >result &&
  34        >expect &&
  35        test_cmp expect result
  36'
  38test_expect_success 'setup roots, merges and octopuses' '
  40        git checkout --orphan newroot &&
  42        test_commit five &&
  43        git checkout -b sidebranch two &&
  44        test_commit six &&
  45        git checkout -b anotherbranch three &&
  46        test_commit seven &&
  47        git checkout -b yetanotherbranch four &&
  48        test_commit eight &&
  49        git checkout master &&
  50        test_merge normalmerge newroot &&
  51        test_tick &&
  52        git merge -m tripus sidebranch anotherbranch &&
  53        git tag tripus &&
  54        git checkout -b tetrabranch normalmerge &&
  55        test_tick &&
  56        git merge -m tetrapus sidebranch anotherbranch yetanotherbranch &&
  57        git tag tetrapus &&
  58        git checkout master
  59'
  60test_expect_success 'rev-list roots' '
  62        check_revlist "--max-parents=0" one five
  64'
  65test_expect_success 'rev-list no merges' '
  67        check_revlist "--max-parents=1" one eight seven six five four three two &&
  69        check_revlist "--no-merges" one eight seven six five four three two
  70'
  71test_expect_success 'rev-list no octopuses' '
  73        check_revlist "--max-parents=2" one normalmerge eight seven six five four three two
  75'
  76test_expect_success 'rev-list no roots' '
  78        check_revlist "--min-parents=1" tetrapus tripus normalmerge eight seven six four three two
  80'
  81test_expect_success 'rev-list merges' '
  83        check_revlist "--min-parents=2" tetrapus tripus normalmerge &&
  85        check_revlist "--merges" tetrapus tripus normalmerge
  86'
  87test_expect_success 'rev-list octopus' '
  89        check_revlist "--min-parents=3" tetrapus tripus
  91'
  92test_expect_success 'rev-list ordinary commits' '
  94        check_revlist "--min-parents=1 --max-parents=1" eight seven six four three two
  96'
  97test_expect_success 'rev-list --merges --no-merges yields empty set' '
  99        check_revlist "--min-parents=2 --no-merges" &&
 101        check_revlist "--merges --no-merges" &&
 102        check_revlist "--no-merges --merges"
 103'
 104test_expect_success 'rev-list override and infinities' '
 106        check_revlist "--min-parents=2 --max-parents=1 --max-parents=3" tripus normalmerge &&
 108        check_revlist "--min-parents=1 --min-parents=2 --max-parents=7" tetrapus tripus normalmerge &&
 109        check_revlist "--min-parents=2 --max-parents=8" tetrapus tripus normalmerge &&
 110        check_revlist "--min-parents=2 --max-parents=-1" tetrapus tripus normalmerge &&
 111        check_revlist "--min-parents=2 --no-max-parents" tetrapus tripus normalmerge &&
 112        check_revlist "--max-parents=0 --min-parents=1 --no-min-parents" one five
 113'
 114test_expect_success 'dodecapus' '
 116        roots= &&
 118        for i in 1 2 3 4 5 6 7 8 9 10 11
 119        do
 120                git checkout -b root$i five &&
 121                test_commit $i &&
 122                roots="$roots root$i" ||
 123                return
 124        done &&
 125        git checkout master &&
 126        test_tick &&
 127        git merge -m dodecapus $roots &&
 128        git tag dodecapus &&
 129        check_revlist "--min-parents=4" dodecapus tetrapus &&
 131        check_revlist "--min-parents=8" dodecapus &&
 132        check_revlist "--min-parents=12" dodecapus &&
 133        check_revlist "--min-parents=13" &&
 134        check_revlist "--min-parents=4 --max-parents=11" tetrapus
 135'
 136test_expect_success 'ancestors with the same commit time' '
 138        test_tick_keep=$test_tick &&
 140        for i in 1 2 3 4 5 6 7 8; do
 141                test_tick=$test_tick_keep
 142                test_commit t$i
 143        done &&
 144        git rev-list t1^! --not t$i >result &&
 145        >expect &&
 146        test_cmp expect result
 147'
 148test_done