From e0ca3d3402b00edb8ea3580afa1d171d07b6e246 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Fri, 15 Nov 2024 11:44:08 -0500 Subject: [PATCH] git: add div script 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 --- links/bin/git-div | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 links/bin/git-div diff --git a/links/bin/git-div b/links/bin/git-div new file mode 100755 index 00000000..75749f90 --- /dev/null +++ b/links/bin/git-div @@ -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/-/ /') [] [ []] + +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 "$@"