Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: barretenberg PR migrate tool #1193

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions scripts/migrate_barretenberg_branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash
set -eu

# Usage: ./this.sh <branch> <commit_message>
# Script for migrating PRs from barretenberg repo to aztec-packages.
# Meant to be used from master with a branch name that exists on barretenberg repo but not aztec-packages.
# You can change the commit message after with git commit --amend if needed.

# Display usage if not enough arguments
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <branch> <commit_message>"
exit 1
fi

# Check for unstaged changes
if ! git diff-index --quiet HEAD --; then
echo "Error: You have unstaged changes. Please commit or stash them before running git_subrepo.sh."
exit 1
fi

BRANCH="$1"
COMMIT_MESSAGE="$2"
SUBREPO_PATH=circuits/cpp/barretenberg # can be changed to another subrepo if useful

SCRIPT_DIR=$(dirname "$(realpath "$0")")
cd "$SCRIPT_DIR"/..

echo "(branch migrate) Switching to a new branch named '$BRANCH' (this branch can't already exist)"

# Check if branch already exists
if git rev-parse --verify "$BRANCH" >/dev/null 2>&1; then
echo "Error: Aztec branch '$BRANCH' already exists. Please delete it with 'git branch -D $BRANCH' if you are sure you don't need it."
exit 1
fi

git checkout -b "$BRANCH"

echo "(branch migrate) Pulling from upstream barretenberg repo. If this doesn't work, your barretenberg branch may need to merge barretenberg master."
# note: we use force with the assumption that people don't care about their subrepo stash branch
if ! scripts/git_subrepo.sh pull "$SUBREPO_PATH" --branch=$BRANCH --force; then
echo "Error: Failed to pull from upstream barretenberg repo. Check your branch name or network connection."
exit 1
fi

echo "(branch migrate) Automatic git data fix"
# Tosses away the .gitrepo changes, as those we only want if pulling from barretenberg master, not PRs (which will go in as aztec commits).
# because git-subrepo uses 'git rm -r', we fix up .gitmodules after as well. This is an edge-case gotcha using
# git submodules along with git-subrepo.

git checkout HEAD^ -- "$SUBREPO_PATH"/.gitrepo .gitmodules

if ! git commit --amend -m "$COMMIT_MESSAGE"; then
echo "Error: Failed to commit changes. Check your commit message."
exit 1
fi
echo "(branch migrate) All done. You can now 'git push origin HEAD' and click to create a PR on aztec. Changes will then automatically go into barretenberg when merged."