/
git-incoming
executable file
·48 lines (37 loc) · 1.36 KB
/
git-incoming
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# vim :set ft=sh
# Show the changes on the remote that would be pulled in.
# The script fetches all the changes first.
#
# If this script is in your $PATH it can be called like this:
#
# git incoming
#
# The script requires git and ruby to be installed on your system.
#
# Copied from: https://raw.github.com/juretta/bin/master/git-incoming
# Return the name of the current branch
function current_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/';
}
CURRENT_BRANCH=`current_branch`
# What branch are we tracking?
TRACKING=$(git config branch.${CURRENT_BRANCH}.merge | ruby -ne 'print $_.gsub(/refs\/heads\//, "").strip')
# What's the name of the remote?
REMOTE=$(git config branch.${CURRENT_BRANCH}.remote)
# Log options
OPTS="--pretty=oneline --abbrev-commit --decorate"
# URL of the remote we are tracking
REMOTE_URL=$(git remote -v | ruby -e "puts STDIN.each_line.grep(/^${REMOTE}/).first.split[1]")
# Fetch the changes from the remote.
echo "Fetching changes from '"${REMOTE}"' (${REMOTE_URL})"
git fetch -q
# E.g. for 'master':
# git log master..origin/master
CHANGES=(env PAGER="" git log --color --exit-code $OPTS ${CURRENT_BRANCH}..${REMOTE}/${TRACKING})
if [ $? -eq 0 ]; then
echo "No changes on ${REMOTE} that are not already available on this branch."
else
echo "Changes on ${REMOTE}:"
echo $CHANGES
fi