Created
April 19, 2013 07:24
-
-
Save puttin/5418677 to your computer and use it in GitHub Desktop.
a shell script help me to view code diff on my jailbreak iPad. View more detail on [View code with your iPad and git](http://puttin.github.io/2013/04/18/view-code-with-your-ipad-and-git/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#default: diff last 2 commit | |
count=2 | |
#default: check next commit | |
upordown=1 | |
while getopts "u:d:" arg | |
do | |
case $arg in | |
u) | |
#echo "u's arg:$OPTARG" | |
count=$OPTARG | |
upordown=1 | |
;; | |
d) | |
count=$OPTARG | |
upordown=-1 | |
;; | |
?) | |
echo "unkonw argument" | |
exit 1 | |
;; | |
esac | |
done | |
#project dir | |
cd ~/Textastic/Documents/ViewDeck; | |
#cd ~/Repo/PWLoadMoreTableFooter | |
#get current_commit | |
git clean -dxf | |
#git checkout -b viewdiff #just in case there is no "viewdiff" branch | |
git checkout viewdiff | |
current_commit=$(git log --pretty=format:%H -1) | |
#get destination commit | |
git clean -dxf | |
git checkout master | |
line=$(git log --pretty=format:%H|grep -n "$current_commit"|cut -d ":" -f 1) | |
destination=$[$line-$[$upordown*$[$count-1]]] | |
destination_commit=$(git log --pretty=format:%H|sed -n "$destination"p) | |
#echo "line:$line destination:$destination" | |
git clean -dxf | |
git checkout viewdiff | |
git reset --hard $destination_commit | |
echo "current_commit:$current_commit" | |
echo "destination_commit:$destination_commit" | |
FILE="../result.diff" | |
rm $FILE | |
if [[ upordown -eq 1 ]]; then | |
echo "up" | |
git diff $current_commit $destination_commit > $FILE #git version:1.5.6 don't have -W option | |
#git diff -W $current_commit $destination_commit > $FILE | |
elif [[ upordown -eq -1 ]]; then | |
echo "down" | |
git diff $destination_commit $current_commit > $FILE | |
#git diff -W $destination_commit $current_commit > $FILE | |
else | |
echo "ERROR!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment