Skip to content

Instantly share code, notes, and snippets.

@iillyyaa
Created August 25, 2021 17:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iillyyaa/2b64b430a153c161e6b02d03108e3651 to your computer and use it in GitHub Desktop.
Save iillyyaa/2b64b430a153c161e6b02d03108e3651 to your computer and use it in GitHub Desktop.
#!/bin/bash
usage() {
cat <<-EOF
git missing [-h] [--theirs] [--mine] [[remote/]branch]
EOF
}
git-missing() {
local do_both=1
local do_mine=0
local do_theirs=0
local refarg=
while [ $# -ne 0 ]; do
case "${1}" in
-h|--help)
usage
exit 0
;;
--the|--thei|--their|--theirs)
do_both=0
do_theirs=1
echo got theirs
;;
--min|--mine)
do_both=0
do_mine=1
echo got mine
;;
-*)
echo "Invalid argument: ${1}"
usage
exit 1
;;
*)
if [[ -n "${refarg}" ]]; then
echo "Unexpected argument: ${1}"
usage
exit 1
fi
refarg=${1}
;;
esac
shift
done
local mine="$(git rev-parse --abbrev-ref HEAD)"
local remote="$(git config --local branch.${mine}.remote)"
local theirs="${refarg:-${remote_ref:-origin}/${mine}}"
if [[ "${theirs}" =~ .+/.+ ]]; then
local remote="${theirs%%/*}"
local branch="${theirs#*/}"
if [[ -n "${remote}" ]]; then
git fetch "${remote}" "${branch}" || exit $?
fi
fi
if [[ "${do_both}" == 1 || "${do_theirs}" == 1 ]]; then
printf "\nTheirs: $t\n==============\n"
git --no-pager log "${mine}..${theirs}" || exit $?
printf "\n"
fi
if [[ "${do_both}" == 1 || "${do_mine}" == 1 ]]; then
printf "\nMine: ${mine}\n==============\n"
git --no-pager log "${theirs}..${mine}" || exit $?
fi
}
git-missing "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment