Skip to content

Commit 4f0cd4b

Browse files
committed
add update-repos script, actually merge all the repos
1 parent db3ef5c commit 4f0cd4b

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

util/update-repos.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/zsh
2+
3+
# For each subrepo branch, pulls in any new commits from the upstream remote.
4+
# Then merges any updated branches back into the current branch.
5+
6+
typeset -A repos=(
7+
["embed"]="git@github.com:jpolitz/pyret-embed.git"
8+
["vscode"]="git@github.com:jpolitz/pyret-parley-vscode.git"
9+
["npm"]="git@github.com:brownplt/pyret-npm.git"
10+
["pyret.org"]="git@github.com:brownplt/pyret.org.git"
11+
["docs"]="git@github.com:brownplt/pyret-docs.git"
12+
["codemirror-mode"]="git@github.com:brownplt/pyret-codemirror-mode.git"
13+
["code.pyret.org"]="git@github.com:brownplt/code.pyret.org.git"
14+
["lang"]="git@github.com:brownplt/pyret-lang.git"
15+
)
16+
17+
set -e
18+
19+
start_branch=$(git rev-parse --abbrev-ref HEAD)
20+
updated=()
21+
22+
# Return to the starting branch on exit (covers both success and error paths).
23+
# If a merge conflict left us in MERGING state, abort it first so checkout works.
24+
cleanup() {
25+
local git_dir
26+
git_dir=$(git rev-parse --git-dir 2>/dev/null) || return
27+
if [[ -f "$git_dir/MERGE_HEAD" ]]; then
28+
echo "Aborting in-progress merge..."
29+
git merge --abort
30+
fi
31+
git checkout "$start_branch"
32+
}
33+
trap cleanup EXIT
34+
35+
for branch in "${(@k)repos}"; do
36+
upstream="${repos[$branch]}"
37+
git checkout "$branch"
38+
before=$(git rev-parse HEAD)
39+
40+
echo "==> Checking $branch ($upstream)"
41+
git pull --no-ff "$upstream"
42+
43+
after=$(git rev-parse HEAD)
44+
updated+=("$branch")
45+
done
46+
47+
# Back to start before merging (trap will fire on EXIT but we do it explicitly
48+
# here so the merges happen on the right branch)
49+
trap - EXIT
50+
git checkout "$start_branch"
51+
52+
echo ""
53+
echo "==> Merging updated branches: ${updated[*]}"
54+
for branch in "${updated[@]}"; do
55+
git merge --no-ff "$branch" -m "Merge branch '$branch'"
56+
done
57+
58+
echo ""
59+
echo "Done."

0 commit comments

Comments
 (0)