Permalink
Browse files

Add divergence, goodness, and mergetool from garybernhardt's repo

  • Loading branch information...
1 parent ba13219 commit 0b535c60c8e17e2e82ba1b94d63947c230781750 @StephenBrown2 committed Mar 23, 2013
Showing with 130 additions and 0 deletions.
  1. +60 −0 bin/git-divergence
  2. +4 −0 bin/git-goodness
  3. +31 −0 bin/gn
  4. +1 −0 bin/gn.py
  5. +21 −0 create-links
  6. +10 −0 gitconfig
  7. +3 −0 sh_aliases
View
@@ -0,0 +1,60 @@
+#!/bin/bash
+
+set -e
+
+(
+ function branch() {
+ git branch 2>/dev/null | grep -e '^*' | tr -d '\* '
+ }
+
+ function ensure_valid_ref() {
+ ref=$1
+ (
+ set +e
+ git show-ref $ref > /dev/null
+ if [[ $? == 1 ]]; then
+ echo "$0: bad ref: $ref"
+ exit 1
+ fi
+ )
+ }
+
+ function show_rev() {
+ rev=$1
+ git log -1 $rev --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
+ echo
+ git di $rev^..$rev | diffstat
+ echo
+ }
+
+ if [[ $# == 2 ]]; then
+ LOCAL=$1
+ REMOTE=$2
+ elif [[ $# == 1 ]]; then
+ LOCAL=`branch`
+ REMOTE=$1
+ else
+ LOCAL=`branch`
+ REMOTE=origin/$LOCAL
+ fi
+
+ ensure_valid_ref $LOCAL
+ ensure_valid_ref $REMOTE
+
+ echo "changes from local ${LOCAL} to remote ${REMOTE}:"
+ echo
+
+ echo incoming:
+ echo
+ for rev in `git rev-list $LOCAL..$REMOTE`; do
+ show_rev $rev
+ done
+
+ echo
+ echo outgoing:
+ echo
+ for rev in `git rev-list $REMOTE..$LOCAL`; do
+ show_rev $rev
+ done
+) | less -r
+
View
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+git diff $* | gn
+
View
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+
+#
+# Print a diff summary like:
+#
+# $ git diff 'master~10..master' | gn
+# 293 lines of diff
+# 185 lines added
+# 19 lines removed
+# +166 lines net change
+
+import sys, os, re, fileinput
+
+def get_lines(diff_lines):
+ # Added lines start with '+' (but not '+++', because that marks a new
+ # file). The same goes for removed lines, except '-' instead of '+'.
+ added_lines = [line for line in diff_lines
+ if line.startswith('+') and not line.startswith('+++')]
+ removed_lines = [line for line in diff_lines
+ if line.startswith('-') and not line.startswith('---')]
+ return added_lines, removed_lines
+
+
+if __name__ == '__main__':
+ diff_lines = list(fileinput.input())
+ added_lines, removed_lines = get_lines(diff_lines)
+ print '%i lines of diff' % len(diff_lines)
+ print '%i lines added' % len(added_lines)
+ print '%i lines removed' % len(removed_lines)
+ print '%+i lines net change' % (len(added_lines) - len(removed_lines))
+
View
View
@@ -8,6 +8,27 @@
for file in [a-zA-Z]* ; do
if [[ "$file" != "create-links" && "$file" != "README" && "$file" != "README.md" ]] ; then
+ if [[ "$file" == "bin" ]]; then
+ if [[ ! -d ~/bin || ! -h ~/bin ]] ; then
+ ln -s `pwd`/bin ~/;
+ elif [[ -d ~/bin && ! -h ~/bin ]]; then
+ for binfile in bin/[a-zA-Z]* ; do
+ if [[ -h ~/"$binfile" ]] ; then
+ echo " Removing symbolic link ~/$binfile"
+ rm ~/"$binfile"
+ elif [[ -a ~/"$binfile" ]] ; then
+ date=$(date '+%FT%T');
+ echo " ~/$binfile exists. Moving it to ~/$binfile.back.$date"
+ mv ~/"$binfile" ~/"$binfile".back.$date || echo "Couldn't move ~/$binfile to ~/$binfile.back.$date!"
+ fi
+
+ echo "ln -s `pwd`/\"$binfile\" ~/\"$binfile\"" && echo "Linked ~/$binfile to `pwd`/$binfile" || echo "Couldn't link ~/$binfile to `pwd`/$binfile!"
+ #ln -s `pwd`/bin/"$binfile" ~/bin/"$binfile" && echo "Linked ~/bin/$binfile to `pwd`/bin/$binfile" || echo "Couldn't link ~/bin/$binfile to `pwd`/bin/$binfile!"
+ done
+ fi
+ continue
+ fi
+
if [[ -h ~/."$file" ]] ; then
echo " Removing symbolic link ~/.$file"
rm ~/."$file"
View
@@ -41,6 +41,13 @@
ds = diff --stat=160,120
dh1 = diff HEAD~1
+ # Divergence (commits we added and commits remote added)
+ div = divergence
+
+ # Goodness (summary of diff lines added/removed/total)
+ gn = goodness
+ gnc = goodness --cached
+
# Fancy logging.
# h = head
# hp = head with patch
@@ -56,3 +63,6 @@
l = "!. ~/.githelpers && git_log_pretty"
la = !git l --all
lg = !git l --graph
+
+[merge]
+ tool = vimdiff
View
@@ -1,5 +1,8 @@
# ~/.sh_aliases
+# Add paths
+export PATH="$HOME/bin:$PATH"
+
# User-specific aliases to be used in a bash or zsh session
alias sudo='PATH=$PATH:/usr/local/bin:/usr/local/sbin:/bin:/usr/bin:/sbin:/usr/sbin /usr/bin/sudo'

0 comments on commit 0b535c6

Please sign in to comment.