Last active
February 22, 2026 16:00
-
-
Save joemiller/fdee0188ca628d4cfeb7d14f9a66b06d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -eou pipefail | |
| TMPDIR="" | |
| GREEN=$'\033[32m' | |
| RESET=$'\033[0m' | |
| msg() { echo "${GREEN}==> $1${RESET}"; } | |
| main() { | |
| local local_repo="${1:?Usage: co-sign-pr <path-to-local-clone> <pr-number>}" | |
| local pr="${2:?Usage: co-sign-pr <path-to-local-clone> <pr-number>}" | |
| local_repo="$(cd "$local_repo" && pwd)" | |
| local remote_url | |
| remote_url="$(git -C "$local_repo" remote get-url origin)" | |
| TMPDIR="$(mktemp -d)" | |
| trap 'rm -rf "$TMPDIR"' EXIT | |
| msg "Cloning from '${local_repo}' -> '${TMPDIR}'..." | |
| git clone --quiet --reference-if-able "$local_repo" "$remote_url" "$TMPDIR" | |
| cd "$TMPDIR" | |
| local gh_repo | |
| gh_repo="$(gh repo view --json nameWithOwner --jq .nameWithOwner)" | |
| local head_branch | |
| head_branch="$(gh pr view "$pr" --repo "$gh_repo" --json headRefName --jq .headRefName)" | |
| msg "Checking out PR #${pr} (${head_branch})..." | |
| git checkout --quiet -B "$head_branch" "origin/$head_branch" | |
| git branch --quiet --set-upstream-to="origin/$head_branch" | |
| local base merge_base count | |
| base="$(gh pr view "$pr" --repo "$gh_repo" --json baseRefName --jq .baseRefName)" | |
| merge_base="$(git merge-base HEAD "origin/${base}")" | |
| count="$(git rev-list --count "${merge_base}..HEAD")" | |
| msg "Re-signing ${count} commit(s)..." | |
| git rebase --quiet --exec 'git commit --amend --no-edit' "$merge_base" | |
| msg "Pushing..." | |
| git push --quiet --force-with-lease | |
| msg "Done. PR #${pr} commits re-signed." | |
| } | |
| main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment