Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 118 lines (96 sloc) 3.5 KB
#!/bin/sh
# Copyright (c) 2012-2013, John Szakmeister <john@szakmeister.net>
#
# Output similar to 'bzr missing'. It shows which revisions you have that the
# other branch doesn't, as well as revision the other branch has that you don't.
# Usage:
# git missing => compares to upstream
# git missing <target> => compares HEAD to <target>
# git missing <source> <target> => compares <source> to <target>
SUBDIRECTORY_OK=1 . "$(git --exec-path)/git-sh-setup" ||
die "Not a git repository."
log_options="--pretty=oneline --abbrev-commit"
git config --get-colorbool color.missing &&
log_options="$log_options --color=always"
# This is duplicated in vcs-status. Make sure to update both if you make
# changes.
_git_infer_publish_branch()
{
local publish_branch
ref="$(git symbolic-ref HEAD 2>/dev/null)"
if [ "$ref" = "" ]; then
return
fi
ref="${ref#refs/heads/}"
case $(git config --get push.default || echo "matching") in
current | simple | matching)
remote=$(git config --get branch.${ref}.pushremote ||
git config --get remote.pushdefault ||
git config --get branch.${ref}.remote)
if [ -z "$remote" -a -n "$(git config --get remote.origin.url 2> /dev/null)" ]; then
remote="origin"
fi
if [ -n "$remote" ]; then
git rev-parse "$remote/$ref" > /dev/null 2>&1 &&
publish_branch="$remote/$ref"
fi
;;
upstream)
publish_branch=$(git rev-parse --symbolic-full-name @{upstream} 2> /dev/null)
if [ $? -eq 0 -a "$publish_branch" != "@{upstream}" ]; then
publish_branch=${publish_branch#refs/remotes/}
else
publish_branch=""
fi
;;
*)
publish_branch=""
;;
esac
echo "$publish_branch"
}
cmd_missing()
{
local firstbranch="$1"
local secondbranch="$2"
if test -z "$firstbranch"; then
# Compare against the publish branch...
publish_branch="$(_git_infer_publish_branch)"
test -z "$publish_branch" &&
die "Can't infer branch to compare to. At least one branch required"
firstbranch="$publish_branch"
fi
git rev-parse "$firstbranch" -- > /dev/null 2>&1 ||
die "Invalid branch or rev: $firstbranch"
if test -z "$secondbranch"; then
secondbranch="$firstbranch"
firstbranch=
else
git rev-parse "$secondbranch" -- > /dev/null 2>&1 ||
die "Invalid branch or rev: $secondbranch"
fi
local extra=$(git rev-list --count --cherry-pick --right-only --no-merges "$secondbranch...$firstbranch")
local missing=$(git rev-list --count --cherry-pick --left-only --no-merges "$secondbranch...$firstbranch")
local output=0
if [ "$extra" != "0" ]; then
output=1
line="You have $extra extra revisions"
echo "$line"
echo "$line" | sed -e 's/./-/g'
git log $log_options --cherry-pick --right-only --no-merges "$secondbranch...$firstbranch"
fi
if [ "$missing" != "0" ]; then
if [ "$extra" != "0" ]; then
echo; echo
fi
output=1
line="You have $missing missing revisions"
echo "$line"
echo "$line" | sed -e 's/./-/g'
git log $log_options --cherry-pick --left-only --no-merges "$secondbranch...$firstbranch"
fi
if [ $output != "0" ]; then
echo
fi
}
cmd_missing "$@" | git_pager