Skip to content

Commit

Permalink
initial upstream script
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkarns committed May 12, 2024
1 parent e3207c4 commit 9422d33
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions script/merge-next-upstream
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#! /usr/bin/env bash

# This is intended to help automate the process of pull changes down from
# ruby-build upstream. It depends on customized rbenv-tags refspec for
# namespacing ruby-build's tags (that way ruby-builds tags don't pollute
# node-build's tags). It re-uses a staging branch where ruby-build's tags
# will be merged into. It finds only the very "next" un-merged ruby-build
# tag; diffs against that and merges it. Then removes the ruby-build defs
# and known scripts that don't apply to node-build. Should leave the
# working copy in a MERGING state.

set -euo pipefail

trace() { (set -x; "$@"); }

clean_branch() {
br=${1:-ruby-build-upstream}
start=${2:-origin/main}

# TODO: explicitly use the rbenv-tags refspec
git fetch --all
git checkout --no-track -b "$br" "$start" ||
[ "$br" = "$(git rev-parse --abbrev-ref HEAD)" ]

# TODO: check clean WC here
}

# FIXME: this is brittle; based on chronological listing of revs
rbenv_tag(){
merged=$1
main=${2:-HEAD}

only=$(test "$merged" = --merged && echo tail || echo head)

trace git for-each-ref 'refs/rbenv-tags/' \
--format '%(refname)' --sort=refname "$merged" "$main" | $only -1
}

prepare(){
{
upstream=${1:-ruby-build/master}
main=${2:-HEAD}

trace git describe --all --exact-match \
"$(trace git merge-base "$main" "$upstream")"

vlast=$(rbenv_tag --merged)
vnext=$(rbenv_tag --no-merged)

trace git diff "${vlast:?}"..."${vnext:?}" \
-- ':!share/' ':!script/*ruby*'
} >&2

echo "$vnext"
}

merge(){
ref=${1:?}

# FIXME: find better way to handle the expected errexit
# TODO: improve commit message
git merge --no-commit --quiet "$ref" || true

# TODO: this stuff should be a custom merge-driver
git rm -rf share/ruby-build
git rm -rf script/update-*ruby
}

# clean_branch ruby-build-update origin/main

rbenv_tag=$(prepare ruby-build/master)

merge "$rbenv_tag"

0 comments on commit 9422d33

Please sign in to comment.