Skip to content

Instantly share code, notes, and snippets.

@zorgiepoo
Last active February 2, 2026 01:02
Show Gist options
  • Select an option

  • Save zorgiepoo/4a658647cbc0a3ccbadedbde84a28b49 to your computer and use it in GitHub Desktop.

Select an option

Save zorgiepoo/4a658647cbc0a3ccbadedbde84a28b49 to your computer and use it in GitHub Desktop.
This script has been superseded by jj cob: https://gist.github.com/zorgiepoo/4615fd7f94cc711f461d7f0c347c5c64
#!/usr/bin/env bash
# Add to jj config:
# [aliases]
# advance = ["util", "exec", "--", "jj-advance.sh"]
set -euo pipefail
target_bookmark=""
target_bookmark_revset=""
usage() {
cat <<EOF
Usage:
jj advance (-b|--bookmark BOOKMARK | -r|--revisions REVSET [default: @-]) [--] [jj commit args...]
Perform a commit and update a bookmark to @-.
By default if no arguments are specified, the bookmark is assumed to be at revision @-.
Otherwise exactly one of -b/--bookmark or -r/--revisions must be specified.
EOF
exit 1
}
# Parse options
while [[ $# -gt 0 ]]; do
case "$1" in
-b|--bookmark)
[[ -n "$target_bookmark_revset" ]] && usage
shift || usage
target_bookmark="$1"
shift
;;
-r|--revisions)
[[ -n "$target_bookmark" ]] && usage
shift || usage
target_bookmark_revset="$1"
shift
;;
--)
shift
break
;;
-*)
echo "Unknown option: $1" >&2
usage
;;
*)
break
;;
esac
done
# Default to @- if neither was specified
if [[ -z "$target_bookmark" && -z "$target_bookmark_revset" ]]; then
target_bookmark_revset="@-"
fi
# Resolve bookmark from revset if needed
if [[ -z "$target_bookmark" ]]; then
bookmarks="$(
jj --ignore-working-copy log \
--revisions "$target_bookmark_revset" \
--no-graph \
--template local_bookmarks
)"
# Normalize whitespace
read -r -a bookmark_array <<<"$bookmarks"
case "${#bookmark_array[@]}" in
0)
echo "No local bookmarks found at revision: $target_bookmark_revset" >&2
exit 1
;;
1)
target_bookmark="${bookmark_array[0]}"
;;
*)
echo "Multiple local bookmarks found at revision $target_bookmark_revset:" >&2
for b in "${bookmark_array[@]}"; do
echo " $b" >&2
done
echo "Please specify one with --bookmark." >&2
exit 1
;;
esac
fi
jj commit "$@"
jj --ignore-working-copy bookmark move "$target_bookmark" --to "@-"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment