CHANGES: update v4.0.0 release notes draft
[git-cola.git] / test / short_branch_overlapping.sh
blob3ae0e084ae9ff6795e37242adbfcd2e1a8e19419
1 #!/bin/bash
2 folder=tmp/a_repo
4 nodeI=0
6 function node() {
7 n=$nodeI
8 nodeI=$((nodeI+1))
10 touch $n >> /dev/null
11 git add $n >> /dev/null
12 if ! [ "$1" == "" ] ; then
13 n=$1
15 git commit -m node-$n- >> /dev/null
16 if ! [ "$1" == "" ] ; then
17 git tag -m "" $n >> /dev/null
21 function get_SHA1() {
22 git log --all --grep node-$1- | grep commit | sed -e 's/commit //'
25 function goto() {
26 SHA1=$(get_SHA1 $1)
27 git checkout $SHA1 -b $2 >> /dev/null
30 function merge() {
31 n=$nodeI
32 nodeI=$((nodeI+1))
34 SHA1=$(get_SHA1 $1)
35 git merge --no-ff $SHA1 -m node-$n- >> /dev/null
38 function range() {
39 i=$1
40 I=$2
41 res=$i
42 while [[ i -lt I ]] ; do
43 i=$((i+1))
44 res="$res $i"
45 done
46 echo $res
49 function nodes() {
50 I=$(($1-1))
51 for i in $(range 0 $I) ; do
52 node
53 done
56 rm -rf "$folder"
57 mkdir "$folder"
58 cd "$folder"
60 git init
61 git symbolic-ref HEAD refs/heads/main
63 # Tags are used to get difference between row and generation values.
64 # Branches main & b2 occupied 2 rows per generation because of tags.
65 # Branches b0 is at the left of tags. Therefore, b0 uses 1 row per generation.
66 # The same is for b1 too. The b1 is short but tag 'b1' cannot be placed
67 # right at the row the branch ends, because the tags at the right were already
68 # placed (they have less generation value). Hence, a gap between last two
69 # commits of b1 is big. Let b0 forks at a row inside the gap. The fork commit
70 # have greater generation than last commit of b1. Hence, it is placed after.
71 # Because of the bug, making many enough branches starting from the fork will
72 # manage to overlapping of last commit of b1 and a commit of a branch.
74 node tag0
75 node tag1
76 node tag2
77 node tag3
78 node tag4
79 nodes 1
81 goto tag0 b0
82 nodes 8
83 b0_head=$n
85 goto tag0 b1
86 nodes 5
88 goto tag0 b2
89 nodes 10
91 git checkout b0
92 nodes 5
94 goto $b0_head b5
95 nodes 5
97 goto $b0_head b6
98 nodes 5
100 goto $b0_head b7
101 nodes 5
103 git checkout b2
105 ../../../bin/git-dag --all &