- Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathcommon.sh
108 lines (87 loc) · 2.62 KB
/
common.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/sh
# Copyright 2018 The Cockroach Authors.
#
# Use of this software is governed by the CockroachDB Software License
# included in the /LICENSE file.
# Initialize a test.
functiontest_init() {
PYTHON=${PYTHON:-python}
# We fix all the git per-commit parameters so that the repo structure
# becomes deterministic.
date="Sun Apr 22 19:26:11 2018 +0200"
author="$t <$t@example.com>"
export GIT_COMMITTER_DATE=$date
export GIT_COMMITTER_NAME=$t
export GIT_COMMITTER_EMAIL=$t@example.com
flags=(--date="$date" --author="$author")
rm -rf $t
mkdir $t
}
# Initialize the repository. Tag the initial commit.
functioninit_repo() {
git init
touch foo; git add foo; git commit "${flags[@]}" -m "initial"; git tag initial
git tag v000-base
}
# Perform some arbitrary change.
# $1 = commit message.
functionmake_change() {
git commit --allow-empty "${flags[@]}" -m "$1"
}
# Mark a branch tip as PR tip.
# $1 = PR number.
functiontag_pr() {
mkdir -p .git/refs/pull/origin
git log --pretty=tformat:%H > .git/refs/pull/origin/$1
}
# Merge a regular branch into the current branch.
# $1 = branch name
functionmerge_branch() {
git merge --no-ff -m "Merge $1 into current"$1
git commit --amend --no-edit "${flags[@]}"
}
# Merge a PR branch into the current branch.
# $1 = branch name
# $2 = PR number
# $3 = PR title
functionmerge_pr() {
branchname=$1
prnum=$2
prtitle=$3
git merge --no-ff -m "Merge #$prnum
$prnum: $prtitle r=foo a=bar
Release note (core change): this must not be included.
Co-authored-by: invisible <invisible@example.com>
"$branchname
git commit --amend --no-edit "${flags[@]}"
# Make a dummy second pr just to compare the PR message.
git checkout -b dummypr
make_change "merge pr canary
Release note: none
"
prnum=$(expr $prnum\* 100)
tag_pr $prnum
git checkout master
git merge --no-ff -m "Merge pull request #$prnum from foo/bar
$prtitle alternate format
" dummypr
git commit --amend --no-edit "${flags[@]}"
git branch -D dummypr
}
functiontest_end() {
# Check the repo layout is correct.
(cd $t&& git log --graph --pretty=oneline) >$t.graph.txt
iftest -z "$rewrite";then
diff -u $t.graph.txt $t.graph.ref.txt
else
mv -f $t.graph.txt $t.graph.ref.txt
fi
# Check the generated release notes.
(cd $t&&$PYTHON$relnotescript --hide-header --hide-downloads-section --from initial --until master "$@") >$t.notes.txt
iftest -z "$rewrite";then
diff -u $t.notes.txt $t.notes.ref.txt
else
mv -f $t.notes.txt $t.notes.ref.txt
fi
rm -rf $t
}