-
Notifications
You must be signed in to change notification settings - Fork 3
/
finish_sync_public_branch.sh
executable file
·62 lines (48 loc) · 1.68 KB
/
finish_sync_public_branch.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
#!/bin/bash
#
# This script should only be called from sync_public_branch.sh,
# or after recovering from a cherry-picking failure of sync_public_branch.sh,
# to complete the sync manually.
#
# parameters:
# BRANCH: master, branch-7.9, ...
#
set -euo pipefail
script_dir=$(dirname "${BASH_SOURCE[0]}")
source "${script_dir}/log_utils.sh"
source "${script_dir}/git_utils.sh"
REF_TREE_ROOT="refs/public_sync"
TIMESTAMP="$(date +"%Y-%m-%d_%H-%M-%S")"
BRANCH="${1}"
WORK_BRANCH="${BRANCH}_work"
PUBLIC_BRANCH="public_${BRANCH}"
PUBLIC_WORK_BRANCH="public_${BRANCH}_work"
pause() {
echo "pause..."
# read
}
# Verify that two refs are "public-equivalent": only have differences in private/
validate_public_equivalent_refs() {
if git diff --name-only "$1" "$2" | grep -v "^private/" >/dev/null; then
error "Illegal state: '$1' and '$2' should only differ in private/"
info "Investigate the output of: git diff --name-only $1 $2"
exit 1
fi
}
info "Reading references..."
LATEST_PUBLIC_BRANCH_REF="$(latest_ref "${REF_TREE_ROOT}/*/${PUBLIC_BRANCH}")"
info "Clearing any empty commit in ${WORK_BRANCH}..."
pause
git filter-branch -f --prune-empty ${LATEST_PUBLIC_BRANCH_REF}..HEAD
# merge ${PUBLIC_WORK_BRANCH} into ${PUBLIC_BRANCH} (ff-only for safety)
info "update ${PUBLIC_BRANCH}"
pause
git checkout "${PUBLIC_BRANCH}"
git merge --ff-only "${PUBLIC_WORK_BRANCH}"
validate_public_equivalent_refs "${PUBLIC_BRANCH}" "${BRANCH}"
info "create refs"
git update-ref "${REF_TREE_ROOT}/${TIMESTAMP}/${BRANCH}" "${BRANCH}"
git update-ref "${REF_TREE_ROOT}/${TIMESTAMP}/${PUBLIC_BRANCH}" "${PUBLIC_BRANCH}"
# log created references
git for-each-ref --count=2 --sort=-refname "${REF_TREE_ROOT}"
info "done"