a94dbd2031de884a080e1657473be3a8212f9682
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Jon Seymour
   4#
   5
   6test_description='Tests git-rev-list --topo-order functionality'
   7
   8. ./test-lib.sh
   9. ../t6000-lib.sh # t6xxx specific functions
  10
  11list_duplicates()
  12{
  13    "$@" | sort | uniq -d
  14}
  15
  16date >path0
  17git-update-cache --add path0
  18save_tag tree git-write-tree
  19on_committer_date "1971-08-16 00:00:00" hide_error save_tag root unique_commit root tree
  20on_committer_date "1971-08-16 00:00:01" save_tag l0 unique_commit l0 tree -p root
  21on_committer_date "1971-08-16 00:00:02" save_tag l1 unique_commit l1 tree -p l0
  22on_committer_date "1971-08-16 00:00:03" save_tag l2 unique_commit l2 tree -p l1
  23on_committer_date "1971-08-16 00:00:04" save_tag a0 unique_commit a0 tree -p l2
  24on_committer_date "1971-08-16 00:00:05" save_tag a1 unique_commit a1 tree -p a0
  25on_committer_date "1971-08-16 00:00:06" save_tag b1 unique_commit b1 tree -p a0
  26on_committer_date "1971-08-16 00:00:07" save_tag c1 unique_commit c1 tree -p b1
  27on_committer_date "1971-08-16 00:00:08" as_author foobar@example.com save_tag b2 unique_commit b2 tree -p b1
  28on_committer_date "1971-08-16 00:00:09" save_tag b3 unique_commit b2 tree -p b2
  29on_committer_date "1971-08-16 00:00:10" save_tag c2 unique_commit c2 tree -p c1 -p b2
  30on_committer_date "1971-08-16 00:00:11" save_tag c3 unique_commit c3 tree -p c2
  31on_committer_date "1971-08-16 00:00:12" save_tag a2 unique_commit a2 tree -p a1
  32on_committer_date "1971-08-16 00:00:13" save_tag a3 unique_commit a3 tree -p a2
  33on_committer_date "1971-08-16 00:00:14" save_tag b4 unique_commit b4 tree -p b3 -p a3
  34on_committer_date "1971-08-16 00:00:15" save_tag a4 unique_commit a4 tree -p a3 -p b4 -p c3
  35on_committer_date "1971-08-16 00:00:16" save_tag l3 unique_commit l3 tree -p a4
  36on_committer_date "1971-08-16 00:00:17" save_tag l4 unique_commit l4 tree -p l3
  37on_committer_date "1971-08-16 00:00:18" save_tag l5 unique_commit l5 tree -p l4
  38on_committer_date "1971-08-16 00:00:19" save_tag m1 unique_commit m1 tree -p a4 -p c3
  39on_committer_date "1971-08-16 00:00:20" save_tag m2 unique_commit m2 tree -p c3 -p a4
  40on_committer_date "1971-08-16 00:00:21" hide_error save_tag alt_root unique_commit alt_root tree
  41on_committer_date "1971-08-16 00:00:22" save_tag r0 unique_commit r0 tree -p alt_root
  42on_committer_date "1971-08-16 00:00:23" save_tag r1 unique_commit r1 tree -p r0
  43on_committer_date "1971-08-16 00:00:24" save_tag l5r1 unique_commit l5r1 tree -p l5 -p r1
  44on_committer_date "1971-08-16 00:00:25" save_tag r1l5 unique_commit r1l5 tree -p r1 -p l5
  45
  46
  47#
  48# note: as of 20/6, it isn't possible to create duplicate parents, so this
  49# can't be tested.
  50#
  51#on_committer_date "1971-08-16 00:00:20" save_tag m3 unique_commit m3 tree -p c3 -p a4 -p c3
  52hide_error save_tag e1 as_author e@example.com unique_commit e1 tree
  53save_tag e2 as_author e@example.com unique_commit e2 tree -p e1
  54save_tag f1 as_author f@example.com unique_commit f1 tree -p e1
  55save_tag e3 as_author e@example.com unique_commit e3 tree -p e2
  56save_tag f2 as_author f@example.com unique_commit f2 tree -p f1
  57save_tag e4 as_author e@example.com unique_commit e4 tree -p e3 -p f2
  58save_tag e5 as_author e@example.com unique_commit e5 tree -p e4
  59save_tag f3 as_author f@example.com unique_commit f3 tree -p f2
  60save_tag f4 as_author f@example.com unique_commit f4 tree -p f3
  61save_tag e6 as_author e@example.com unique_commit e6 tree -p e5 -p f4
  62save_tag f5 as_author f@example.com unique_commit f5 tree -p f4
  63save_tag f6 as_author f@example.com unique_commit f6 tree -p f5 -p e6
  64save_tag e7 as_author e@example.com unique_commit e7 tree -p e6
  65save_tag e8 as_author e@example.com unique_commit e8 tree -p e7
  66save_tag e9 as_author e@example.com unique_commit e9 tree -p e8
  67save_tag f7 as_author f@example.com unique_commit f7 tree -p f6
  68save_tag f8 as_author f@example.com unique_commit f8 tree -p f7
  69save_tag f9 as_author f@example.com unique_commit f9 tree -p f8
  70save_tag e10 as_author e@example.com unique_commit e1 tree -p e9 -p f8
  71
  72hide_error save_tag g0 unique_commit g0 tree
  73save_tag g1 unique_commit g1 tree -p g0
  74save_tag h1 unique_commit g2 tree -p g0
  75save_tag g2 unique_commit g3 tree -p g1 -p h1
  76save_tag h2 unique_commit g4 tree -p g2
  77save_tag g3 unique_commit g5 tree -p g2
  78save_tag g4 unique_commit g6 tree -p g3 -p h2
  79
  80tag l5 > .git/HEAD
  81
  82#
  83# cd to t/trash and use 
  84#
  85#    git-rev-list ... 2>&1 | sed "$(cat sed.script)" 
  86#
  87# if you ever want to manually debug the operation of git-rev-list
  88#
  89echo "$sed_script" | tr ' ' \\012 > sed.script
  90
  91test_expect_success 'rev-list has correct number of entries' 'git-rev-list HEAD | wc -l | tr -s " "' <<EOF
  9219
  93EOF
  94
  95test_output_expect_success 'simple topo order' 'git-rev-list --topo-order  HEAD' <<EOF
  96l5
  97l4
  98l3
  99a4
 100c3
 101c2
 102c1
 103b4
 104a3
 105a2
 106a1
 107b3
 108b2
 109b1
 110a0
 111l2
 112l1
 113l0
 114root
 115EOF
 116
 117test_output_expect_success 'two diamonds topo order (g6)' 'git-rev-list --topo-order  g4' <<EOF
 118g4
 119h2
 120g3
 121g2
 122h1
 123g1
 124g0
 125EOF
 126
 127test_output_expect_success 'multiple heads' 'git-rev-list --topo-order a3 b3 c3' <<EOF
 128b3
 129c3
 130c2
 131b2
 132c1
 133b1
 134a3
 135a2
 136a1
 137a0
 138l2
 139l1
 140l0
 141root
 142EOF
 143
 144test_output_expect_success 'multiple heads, prune at a1' 'git-rev-list --topo-order a3 b3 c3 ^a1' <<EOF
 145b3
 146c3
 147c2
 148b2
 149c1
 150b1
 151a3
 152a2
 153EOF
 154
 155test_output_expect_success 'multiple heads, prune at l1' 'git-rev-list --topo-order a3 b3 c3 ^l1' <<EOF
 156b3
 157c3
 158c2
 159b2
 160c1
 161b1
 162a3
 163a2
 164a1
 165a0
 166l2
 167EOF
 168
 169test_output_expect_success 'cross-epoch, head at l5, prune at l1' 'git-rev-list --topo-order l5 ^l1' <<EOF
 170l5
 171l4
 172l3
 173a4
 174c3
 175c2
 176c1
 177b4
 178a3
 179a2
 180a1
 181b3
 182b2
 183b1
 184a0
 185l2
 186EOF
 187
 188test_output_expect_success 'duplicated head arguments' 'git-rev-list --topo-order l5 l5 ^l1' <<EOF
 189l5
 190l4
 191l3
 192a4
 193c3
 194c2
 195c1
 196b4
 197a3
 198a2
 199a1
 200b3
 201b2
 202b1
 203a0
 204l2
 205EOF
 206
 207test_output_expect_success 'prune near topo' 'git-rev-list --topo-order a4 ^c3' <<EOF
 208a4
 209b4
 210a3
 211a2
 212a1
 213b3
 214EOF
 215
 216test_output_expect_success "head has no parent" 'git-rev-list --topo-order  root' <<EOF
 217root
 218EOF
 219
 220test_output_expect_success "two nodes - one head, one base" 'git-rev-list --topo-order  l0' <<EOF
 221l0
 222root
 223EOF
 224
 225test_output_expect_success "three nodes one head, one internal, one base" 'git-rev-list --topo-order  l1' <<EOF
 226l1
 227l0
 228root
 229EOF
 230
 231test_output_expect_success "linear prune l2 ^root" 'git-rev-list --topo-order  l2 ^root' <<EOF
 232l2
 233l1
 234l0
 235EOF
 236
 237test_output_expect_success "linear prune l2 ^l0" 'git-rev-list --topo-order  l2 ^l0' <<EOF
 238l2
 239l1
 240EOF
 241
 242test_output_expect_success "linear prune l2 ^l1" 'git-rev-list --topo-order  l2 ^l1' <<EOF
 243l2
 244EOF
 245
 246test_output_expect_success "linear prune l5 ^a4" 'git-rev-list --topo-order  l5 ^a4' <<EOF
 247l5
 248l4
 249l3
 250EOF
 251
 252test_output_expect_success "linear prune l5 ^l3" 'git-rev-list --topo-order  l5 ^l3' <<EOF
 253l5
 254l4
 255EOF
 256
 257test_output_expect_success "linear prune l5 ^l4" 'git-rev-list --topo-order  l5 ^l4' <<EOF
 258l5
 259EOF
 260
 261test_output_expect_success "max-count 10 - topo order" 'git-rev-list --topo-order  --max-count=10 l5' <<EOF
 262l5
 263l4
 264l3
 265a4
 266c3
 267c2
 268c1
 269b4
 270a3
 271a2
 272EOF
 273
 274test_output_expect_success "max-count 10 - non topo order" 'git-rev-list --max-count=10 l5' <<EOF
 275l5
 276l4
 277l3
 278a4
 279b4
 280a3
 281a2
 282c3
 283c2
 284b3
 285EOF
 286
 287test_output_expect_success '--max-age=c3, no --topo-order' "git-rev-list --max-age=$(commit_date c3) l5" <<EOF
 288l5
 289l4
 290l3
 291a4
 292b4
 293a3
 294a2
 295c3
 296EOF
 297
 298#
 299# this test fails on --topo-order - a fix is required
 300#
 301#test_output_expect_success '--max-age=c3, --topo-order' "git-rev-list --topo-order --max-age=$(commit_date c3) l5" <<EOF
 302#l5
 303#l4
 304#l3
 305#a4
 306#c3
 307#b4
 308#a3
 309#a2
 310#EOF
 311
 312test_output_expect_success 'one specified head reachable from another a4, c3, --topo-order' "list_duplicates git-rev-list --topo-order a4 c3" <<EOF
 313EOF
 314
 315test_output_expect_success 'one specified head reachable from another c3, a4, --topo-order' "list_duplicates git-rev-list --topo-order c3 a4" <<EOF
 316EOF
 317
 318test_output_expect_success 'one specified head reachable from another a4, c3, no --topo-order' "list_duplicates git-rev-list a4 c3" <<EOF
 319EOF
 320
 321test_output_expect_success 'one specified head reachable from another c3, a4, no --topo-order' "list_duplicates git-rev-list c3 a4" <<EOF
 322EOF
 323
 324test_output_expect_success 'graph with c3 and a4 parents of head' "list_duplicates git-rev-list m1" <<EOF
 325EOF
 326
 327test_output_expect_success 'graph with a4 and c3 parents of head' "list_duplicates git-rev-list m2" <<EOF
 328EOF
 329
 330test_expect_success "head ^head --topo-order" 'git-rev-list --topo-order  a3 ^a3' <<EOF
 331EOF
 332
 333test_expect_success "head ^head no --topo-order" 'git-rev-list a3 ^a3' <<EOF
 334EOF
 335
 336test_output_expect_success 'simple topo order (l5r1)' 'git-rev-list --topo-order  l5r1' <<EOF
 337l5r1
 338r1
 339r0
 340alt_root
 341l5
 342l4
 343l3
 344a4
 345c3
 346c2
 347c1
 348b4
 349a3
 350a2
 351a1
 352b3
 353b2
 354b1
 355a0
 356l2
 357l1
 358l0
 359root
 360EOF
 361
 362test_output_expect_success 'simple topo order (r1l5)' 'git-rev-list --topo-order  r1l5' <<EOF
 363r1l5
 364l5
 365l4
 366l3
 367a4
 368c3
 369c2
 370c1
 371b4
 372a3
 373a2
 374a1
 375b3
 376b2
 377b1
 378a0
 379l2
 380l1
 381l0
 382root
 383r1
 384r0
 385alt_root
 386EOF
 387
 388test_output_expect_success "don't print things unreachable from one branch" "git-rev-list a3 ^b3 --topo-order" <<EOF
 389a3
 390a2
 391a1
 392EOF
 393
 394test_output_expect_success "--topo-order a4 l3" "git-rev-list --topo-order a4 l3" <<EOF
 395l3
 396a4
 397c3
 398c2
 399c1
 400b4
 401a3
 402a2
 403a1
 404b3
 405b2
 406b1
 407a0
 408l2
 409l1
 410l0
 411root
 412EOF
 413
 414#
 415#
 416
 417test_done