aboutsummaryrefslogtreecommitdiff
path: root/tmuxrdr/scripts/sync-upstream
blob: 44c1b010cfc8fea5ad4ce1828bcb16790c5a7349 (plain)
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
#!/bin/bash

# Move tmuxrdr onto a newer herdr release: rebase the tmuxrdr commits from the
# release they sit on onto the new one.
#
#   tmuxrdr/scripts/sync-upstream            newest stable release (vX.Y.Z)
#   tmuxrdr/scripts/sync-upstream v0.9.4     that release
#
# Releases, not upstream's master: a release is what Homebrew ships, so a
# tmuxrdr build speaks the same protocol as any stock herdr server around it.
# The base is the newest release tag behind HEAD; the tmuxrdr commits are
# everything after it. The branch as it was is kept as tmuxrdr-on-<old tag>,
# so a bad rebase costs nothing: `git switch -C tmuxrdr tmuxrdr-on-<old tag>`.
# rerere is on in this checkout, so a conflict resolved once is resolved again
# by itself on the next release.

set -euo pipefail

cd "$(dirname "$0")/../.."
branch="tmuxrdr"
target="${1:-}"

die() { >&2 echo "ERROR: $*"; exit 1; }

[[ "$(git symbolic-ref --short -q HEAD)" == "$branch" ]] || die "check out $branch first"
[[ -z "$(git status --porcelain)" ]] || die "uncommitted changes; commit or stash them first"

git fetch --quiet --tags --prune upstream

old="$(git describe --tags --abbrev=0 --match 'v[0-9]*' HEAD)"
if [[ -z "$target" ]]; then
  target="$(git tag -l 'v[0-9]*' --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)"
fi
git rev-parse -q --verify "refs/tags/$target^{commit}" >/dev/null || die "no release tag $target"

if [[ "$target" == "$old" ]]; then
  echo "up to date: $branch is on $old"
  exit 0
fi
[[ "$(printf '%s\n' "$old" "$target" | sort -V | tail -n 1)" == "$target" ]] \
  || die "$target is older than $old, the release $branch is on"

echo "$branch: $(git rev-list --count "$old..HEAD") commits on $old"
git log --oneline --reverse "$old..HEAD" | sed 's/^/  /'
echo "rebasing onto $target ($(git rev-list --count "$old..$target") upstream commits)"

backup="$branch-on-$old"
git branch -f "$backup" HEAD

if ! git rebase --onto "$target" "$old" "$branch"; then
  cat <<EOF

The rebase stopped on a conflict -- in a code patch, since everything else
lives in tmuxrdr/, which upstream never touches.
  git status                      what conflicts
  ... resolve, git add, then:     git rebase --continue
  git rebase --abort              give up: $branch goes back as it was
The branch before the rebase is also kept as $backup.
EOF
  exit 1
fi

echo
echo "$branch is on $target; the old one is kept as $backup."
installed="$("${HERDR:-herdr}" --version 2>/dev/null | awk '{print "v" $2}')"
if [[ "$installed" != "$target" ]]; then
  echo "herdr on PATH is ${installed:-missing}, not $target: test against $target"
  echo "(upgrade it, or build this checkout -- README.md) before trusting test-e2e."
fi
HERDR_CONFIG_PATH="$PWD/tmuxrdr/config/config.toml" "${HERDR:-herdr}" config check \
  || echo "config check found issues against the herdr on PATH; see above"
echo "Next: tmuxrdr/scripts/test-e2e"