Skip to content

Instantly share code, notes, and snippets.

@EBNull
Created August 17, 2024 02:20
Show Gist options
  • Save EBNull/ef5777307cfc375582e30192599f5fef to your computer and use it in GitHub Desktop.
Save EBNull/ef5777307cfc375582e30192599f5fef to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eu
REVS='roots(~ancestors(roots(trunk())))'
DEST='trunk()'
branches_to_delete() {
# Return all branches that point to immutable heads, except for the main one.
# Branches may have changed on the remote (e.g. deleted), so remove the asterisk marker.
jj log --no-graph -T 'local_branches.join("\n")' -r 'immutable_heads()' | grep -v -E '^(main|master|trunk)$' | sed 's/*$//'
}
preview() {
echo "Will rebase:"
echo
jj --no-pager log -r "$REVS"
echo -e "\nonto:\n"
jj --no-pager log -r "$DEST"
echo
echo "Will delete:"
branches_to_delete
}
go() {
jj rebase --skip-empty -s "all:$REVS" -d "$DEST"
branches_to_delete | xargs -r jj branch delete
}
while (($#)); do
case "$1" in
"go" | "preview")
$1
exit $?
;;
"-f")
git fetch
;;
"--pull")
git fetch
;;
*)
echo "unknown command or arg"
exit 2
;;
esac
shift
done
go --pull
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment