-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-from-upstream.sh
More file actions
executable file
·59 lines (47 loc) · 1.45 KB
/
Copy pathupdate-from-upstream.sh
File metadata and controls
executable file
·59 lines (47 loc) · 1.45 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
#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
cd "$repo_root"
manifest="$repo_root/scripts/local/upstream-picks.txt"
branch="$(git symbolic-ref --quiet --short HEAD || true)"
if [[ -z "$branch" ]]; then
echo "error: not on a branch" >&2
exit 1
fi
if [[ "$branch" != local/* && "$branch" != main ]]; then
echo "error: expected main or a local/* product branch, got '$branch'" >&2
exit 1
fi
if ! git diff --quiet || ! git diff --cached --quiet; then
echo "error: worktree is dirty; commit or stash changes before updating" >&2
exit 1
fi
if [[ ! -f "$manifest" ]]; then
echo "error: upstream import manifest not found: $manifest" >&2
exit 1
fi
echo "Fetching upstream"
git fetch upstream --tags
echo "Merging upstream/main into $branch"
git merge --no-edit upstream/main
echo
echo "Applying carried commit stack from $(basename "$manifest")"
while IFS= read -r raw_line || [[ -n "$raw_line" ]]; do
line="${raw_line%%#*}"
pick_commit="$(printf '%s' "$line" | xargs)"
if [[ -z "$pick_commit" ]]; then
continue
fi
if ! git cat-file -e "$pick_commit^{commit}" 2>/dev/null; then
echo "error: carried commit '$pick_commit' does not exist" >&2
exit 1
fi
if git merge-base --is-ancestor "$pick_commit" HEAD; then
echo "- $pick_commit already present"
continue
fi
echo "- cherry-picking $pick_commit"
git cherry-pick "$pick_commit"
done <"$manifest"
echo
"$repo_root/scripts/local/rebuild-path-code.sh"