#!/bin/sh # Switch to the more diverged of master and current dev Emacs branches. # # This automates the process of choosing between the Emacs development # branch (e.g., 'emacs-27') and 'master' branch when building for use, # since for use one just wants whichever branch has more unique changes. # When building for development use, one would choose whichever branch # is most appropriate for the specific dev work, obviously. NAME1="master" NAME2="emacs-27" git checkout --quiet ${NAME1} && git pull git checkout --quiet ${NAME2} && git pull echo "" TMPFILE="peb-$$.tmp" git show-branch ${NAME1} ${NAME2} > ${TMPFILE} COUNT1=`awk '/^--$/,EOF { print $0 }' "${TMPFILE}" | grep -E "( \* |\+ |\* | \+ )\[${NAME1}([~^]|])" | wc -l` COUNT2=`awk '/^--$/,EOF { print $0 }' "${TMPFILE}" | grep -E "( \* |\+ |\* | \+ )\[${NAME2}([~^]|])" | wc -l` rm "${TMPFILE}" if [ ${COUNT1} -gt ${COUNT2} ]; then echo "Choosing '${NAME1}' (${COUNT1} unique commits, to ${COUNT2} on '${NAME2}')." git checkout ${NAME1} elif [ ${COUNT2} -gt ${COUNT1} ]; then echo "Choosing '${NAME2}' (${COUNT2} unique commits, to ${COUNT1} on '${NAME1}')." git checkout ${NAME2} else echo "Same: ${COUNT1} unique commits on both branches ('${NAME1}' and '${NAME2}')." echo "Choosing '${NAME1}'." git checkout ${NAME1} fi