Created
August 17, 2024 02:20
-
-
Save EBNull/ef5777307cfc375582e30192599f5fef to your computer and use it in GitHub Desktop.
This file contains 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
#!/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