#!/usr/bin/env bash # Fetch a rusty-kaspa release tag into the Igneum node fork and open the merge on a branch. # Commits nothing. A person reads the conflicts, runs the tests in tools/upstream/README.md, # does the consensus review against docs/spec, and commits. # # Usage: # tools/upstream/sync-upstream.sh [fork-dir] [upstream-url] # tag a rusty-kaspa release tag, for example v2.2.0 # fork-dir default: vendor/igneum-node (relative to the repository root) # upstream-url used only if the fork has no remote named "upstream"; # default: https://github.com/kaspanet/rusty-kaspa.git # # Refuses: a dirty working tree, a merge already in progress, a missing tag, # an existing merge branch. Never touches master and never runs the devnet. set -euo pipefail tag="${1:-}" if [[ -z "$tag" ]]; then echo "usage: $0 [fork-dir] [upstream-url]" >&2 exit 2 fi root="$(cd "$(dirname "$0")/../.." && pwd)" fork="${2:-$root/vendor/igneum-node}" url="${3:-https://github.com/kaspanet/rusty-kaspa.git}" branch="merge/upstream-$tag" base="master" if [[ ! -d "$fork/.git" ]]; then echo "no git repository at $fork" >&2 exit 1 fi cd "$fork" if [[ -n "$(git status --porcelain)" ]]; then echo "refusing: working tree is not clean in $fork" >&2 git status --short >&2 exit 1 fi if [[ -f .git/MERGE_HEAD ]]; then echo "refusing: a merge is already in progress in $fork" >&2 exit 1 fi if git show-ref --verify --quiet "refs/heads/$branch"; then echo "refusing: branch $branch already exists" >&2 exit 1 fi if ! git show-ref --verify --quiet "refs/heads/$base"; then echo "refusing: no local branch $base" >&2 exit 1 fi if ! git remote get-url upstream >/dev/null 2>&1; then echo "adding remote upstream -> $url" git remote add upstream "$url" fi echo "upstream is $(git remote get-url upstream)" echo "fetching tags from upstream" git fetch upstream --tags --prune if ! git rev-parse --verify --quiet "refs/tags/$tag^{commit}" >/dev/null; then echo "refusing: tag $tag not found after fetch. Known release tags:" >&2 git tag --list 'v*' | sort -V | tail -10 >&2 exit 1 fi echo echo "upstream changes in the consensus directories since the fork base (01b532e8):" git log --oneline "01b532e8..$tag" -- consensus crypto/hashes crypto/txscript crypto/addresses protocol/p2p/proto mining || true echo git checkout -q -b "$branch" "$base" echo "on branch $branch (from $base)" set +e git merge --no-commit --no-ff "$tag" status=$? set -e echo conflicts="$(git diff --name-only --diff-filter=U)" if [[ -n "$conflicts" ]]; then echo "merge opened with conflicts in:" echo "$conflicts" | sed 's/^/ /' echo echo "expected conflict files and how to resolve each: tools/upstream/README.md" elif [[ $status -eq 0 ]]; then echo "merge opened cleanly, nothing committed" else echo "git merge exited $status without conflict markers; read the output above" >&2 exit $status fi cat <