]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - bin/git-up
Merge branch 'master' into epic
[dotfiles.git] / bin / git-up
1 #!/bin/sh
2
3 # Usage: git-up
4 # git-reup
5 #
6 # Like git-pull but show a short and sexy log of changes
7 # immediately after merging (git-up) or rebasing (git-reup).
8 #
9 # Inspired by Kyle Neath's `git up' alias:
10 # http://gist.github.com/249223
11
12 set -e
13
14 PULL_ARGS="$@"
15
16 if [ "$(basename $0)" = "git-reup" ]; then
17 # when invoked as git-reup, run as `git pull --rebase ...'
18 PULL_ARGS="--rebase $PULL_ARGS"
19 FETCH_ARGS=""
20 else
21 # when invoked as git-up, run as `git pull ...`
22 PULL_ARGS="--ff-only $PULL_ARGS"
23 if [ " $@" = " " ]; then
24 # when invoked without a repo/head, fetch (and prune) all remotes
25 FETCH_ARGS="--all --prune"
26 fi
27 fi
28
29 HEAD_OLD=$(git log -1 --pretty='format:%H' HEAD)
30 git pull $PULL_ARGS $FETCH_ARGS $@
31 HEAD_NEW=$(git log -1 --pretty='format:%H' HEAD)
32
33 if [ "$HEAD_OLD" != "$HEAD_NEW" ]; then
34 # if HEAD was actually updated...
35 if [ "$(basename $0)" = "git-reup" ]; then
36 # if we're pulling with --rebase, show diffstat of all changes.
37 # not sure why git-pull only does this when merging.
38 echo "Diff:"
39 git --no-pager diff --color --stat ${HEAD_OLD}.. | sed 's/^/ /'
40 fi
41
42 # show an abbreviated commit log of stuff that was just merged.
43 echo "Log:"
44 git log --color --pretty=oneline --abbrev-commit ${HEAD_OLD}.. | sed 's/^/ /'
45 fi