#!/bin/sh
#
## Like git pull but show a short and sexy log of changes after merging or rebasing.
## Source: git-extra-commands

# Usage: git-up
#        git-reup
#
# Like git-pull but show a short and sexy log of changes
# immediately after merging (git-up) or rebasing (git-reup).
#
# Inspired by Kyle Neath's `git up' alias:
# http://gist.github.com/249223
#
# Stolen from Ryan Tomayko
# http://github.com/rtomayko/dotfiles/blob/rtomayko/bin/git-up

set -e

# shellcheck disable=SC2124
PULL_ARGS="$@"

# when invoked as git-reup, run as `git pull --rebase'
# shellcheck disable=SC2086,SC2124
test "$(basename $0)" = "git-reup" &&
PULL_ARGS="--rebase $PULL_ARGS"

# shellcheck disable=SC2086
git pull $PULL_ARGS

# show diffstat of all changes if we're pulling with --rebase. not
# sure why git-pull only does this when merging.
# shellcheck disable=SC2086
test "$(basename $0)" = "git-reup" && {
    echo "Diff:"
    # shellcheck disable=SC1083
    git --no-pager diff --color --stat HEAD@{1}.. |
    sed 's/^/ /'
}

# show an abbreviated commit log of stuff that was just merged.
echo "Log:"
# shellcheck disable=SC1083
git log --color --pretty=oneline --abbrev-commit HEAD@{1}.. |
sed 's/^/  /'