Skip to content

Commit

Permalink
git: add div script
Browse files Browse the repository at this point in the history
Inspired by MJD [1], [2], add my own take on `git div`. I've been using
`graph --boundary @{push}...` and similar along with `sbup` to get a
reckoning of what's happening. This codifies the --boundary graph and
provides me a way to remember what's going on (-v).

[1]: https://github.com/mjdominus/git-util/blob/master/bin/git-vee
[2]: https://blog.plover.com/prog/git-q.html
  • Loading branch information
benknoble committed Nov 15, 2024
1 parent 6629644 commit e0ca3d3
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions links/bin/git-div
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#! /bin/sh

# Inspired by: https://github.com/mjdominus/git-util/blob/master/bin/git-vee

set -eu

OPTIONS_SPEC="\
$(basename -- "$0" | sed -e 's/-/ /') [<options>] [<base=HEAD> [<upstream>]]
Show branch divergence between base and its upstream
--
v verbose: show divergence command"
SUBDIRECTORY_OK=true

# source git-sh-setup for some helpers
set +u
. "$(git --exec-path)"/git-sh-setup
set -u

verbose=
base=@
upstream=

set_upstream() {
if ! upstream="$(git rev-parse --verify --symbolic -q "$base@{push}")"; then
if ! upstream="$(git rev-parse --verify --symbolic -q "$base@{upstream}")"; then
die "could not determine upstream for base $base"
fi
fi
}

main() {
while test $# -gt 0; do
opt="$1"
shift
case "$opt" in
(-v) verbose=1 ;;
(--) break ;;
esac
done
case $# in
(0) : continue ;;
(1) base="$1" ;;
(2) base="$1"; upstream="$2" ;;
(*) printf '%s\n' 'too many arguments' >&2; usage ;;
esac
shift $#

test -z "$upstream" && set_upstream

set -- git graph --boundary --cherry-mark --left-right "$base...$upstream"
test -n "$verbose" && printf '%s\n' "$*" >&2
exec "$@"
}

main "$@"

0 comments on commit e0ca3d3

Please sign in to comment.