Advertisement
Guest User

Untitled

a guest
Feb 1st, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. function print_example() {
  4. echo "Example"
  5. echo " git-diff develop master"
  6. }
  7.  
  8. function print_usage() {
  9. echo "Usage"
  10. echo " git-diff <branch|tag|commit> <branch|tag|commit>"
  11. }
  12.  
  13. if [ "$1" = "--help" ] || [ "$1" = "-h" ] ; then
  14. print_usage
  15. exit 0
  16. fi
  17.  
  18. FROM="$1"
  19. TO="$2"
  20. if [ -z "$FROM" ] || [ -z "$TO" ]; then
  21. echo "Error: missing arguments"
  22. echo ""
  23. print_usage
  24. echo ""
  25. print_example
  26. exit 1
  27. fi
  28.  
  29. if ! [ -d .git ]; then # .git folder exists?
  30. echo "Error: current directory is not a git root directory"
  31. exit 1
  32. fi
  33.  
  34. DIR=${TMPDIR%/}/gitdiff # `%/` removes trailing slash
  35. rm -rf "$DIR"
  36. for i in $(git diff --name-only $FROM $TO) ; do
  37. # Setup folder structure
  38. mkdir -p $DIR/"$FROM"/"$(dirname $i)";
  39. mkdir -p $DIR/"$TO"/"$(dirname $i)";
  40.  
  41. # Get revision of files
  42. git show "$FROM":"$i" > "$DIR"/"$FROM"/$i;
  43. git show "$TO":"$i" > "$DIR"/"$TO"/$i;
  44. done
  45.  
  46. # Use git's difftool or opendiff as alternative
  47. DIFFTOOL=$(expr "$(git config --get diff.tool)" '|' "opendiff")
  48.  
  49. $($DIFFTOOL "$DIR"/"$FROM" "$DIR"/"$TO")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement