-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsync.sh
More file actions
executable file
·134 lines (117 loc) · 3.67 KB
/
Copy pathsync.sh
File metadata and controls
executable file
·134 lines (117 loc) · 3.67 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
source "$(dirname "$0")/common.sh"
############################################################
# Help #
############################################################
show_help()
{
echo "Synchronize downstream repositories from upstream"
echo
echo "Syntax: sync.sh [-h|-d|-y|-p] TARGET"
echo "Options:"
echo " -h Print this help."
echo " -d Dry run (do not push to remote downstream)."
echo " -y Yes-mode (non-interactive: proceed without asking)."
echo " -p PR-mode (push to fork and create PRs instead of pushing directly to downstream)."
echo
echo "Arguments:"
echo " TARGET Target downstream branch"
echo
echo "Example:"
echo " ./sync.sh release-1.12"
echo " ./sync.sh -p release-1.12 # for non-admin users"
echo
}
# Reset in case getopts has been used previously in the shell.
OPTIND=1
dry_run=0
yes_mode=0
pr_mode=0
while getopts "h?dyp" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
d)
dry_run=1
;;
y)
yes_mode=1
;;
p)
pr_mode=1
;;
esac
done
shift $((OPTIND-1))
[ "${1:-}" = "--" ] && shift
if [ "$#" == "0" ]; then
echo "Missing argument: TARGET"
show_help
exit 1
fi
if [ "$#" != "1" ]; then
echo "Too many arguments: $@"
show_help
exit 1
fi
dry_run_text=""
if [[ $dry_run == 1 ]]; then
echo "DRY RUN: remote will not be updated"
dry_run_text=" (dry run)"
fi
target="$1"
echo "Synchronizing \"downstream/$target\" with \"upstream/main${dry_run_text}\". A temporary local branch named \"tmp-$target\" will be created/overwritten."
confirm || exit 1
merge_and_push() {
local repo=$1
local downstream_branch=$2
local upstream_branch=$3
local downstream_repo=$4
local tmp_branch="tmp-$downstream_branch"
git checkout -B $tmp_branch downstream/$downstream_branch
git reset --hard downstream/$downstream_branch
git merge upstream/$upstream_branch
if [[ "$?" != "0" ]]; then
warnings+=("Merge failed in \"$repo\", branch \"$downstream_branch\"; resolve conflicts, merge and push manually.")
elif [[ $dry_run == 1 ]]; then
echo "DRY RUN: skip push $tmp_branch to downstream/$downstream_branch. You can push manually if you wish."
else
confirm "Merge done. Proceed with push?" || return
push_or_pr "${downstream_repo}" "${downstream_branch}" "Sync ${downstream_branch} from upstream"
fi
}
i_cpnt=0
for repo in "${repos[@]}"; do
echo -e "\n\033[1mProcessing $repo\033[0m"
pushd $repo
git fetch upstream
git fetch downstream
git ls-remote --exit-code --heads downstream refs/heads/$target
if [[ "$?" != "0" ]]; then
echo "Branch downstream/$target not found. Create the branches before running sync.sh. You can use new-branches.sh."
exit 1
fi
ds_repo=${downstream_repos[$i_cpnt]}
merge_and_push $repo $target main $ds_repo
if [[ "$repo" == "console-plugin" ]]; then
for variant in "${cp_variants[@]}"; do
echo -e "\n\033[1mVariant: $variant\033[0m"
git diff HEAD --exit-code
if [[ "$?" != "0" ]]; then
warnings+=("Sounds like console-plugin previous merge failed, cannot proceed with this variant. Run again the script after resolving conflicts for syncing next variant.")
else
git ls-remote --exit-code --heads downstream refs/heads/$target-$variant
if [[ "$?" != "0" ]]; then
echo "Branch downstream/$target-$variant not found. Create the branches before running sync.sh. You can use new-branches.sh."
exit 1
fi
merge_and_push $repo $target-$variant main-$variant $ds_repo
fi
done
fi
popd
i_cpnt="$((i_cpnt+1))"
done
print_warnings