Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- function print_example() {
- echo "Example"
- echo " git-diff develop master"
- }
- function print_usage() {
- echo "Usage"
- echo " git-diff <branch|tag|commit> <branch|tag|commit>"
- }
- if [ "$1" = "--help" ] || [ "$1" = "-h" ] ; then
- print_usage
- exit 0
- fi
- FROM="$1"
- TO="$2"
- if [ -z "$FROM" ] || [ -z "$TO" ]; then
- echo "Error: missing arguments"
- echo ""
- print_usage
- echo ""
- print_example
- exit 1
- fi
- if ! [ -d .git ]; then # .git folder exists?
- echo "Error: current directory is not a git root directory"
- exit 1
- fi
- DIR=${TMPDIR%/}/gitdiff # `%/` removes trailing slash
- rm -rf "$DIR"
- for i in $(git diff --name-only $FROM $TO) ; do
- # Setup folder structure
- mkdir -p $DIR/"$FROM"/"$(dirname $i)";
- mkdir -p $DIR/"$TO"/"$(dirname $i)";
- # Get revision of files
- git show "$FROM":"$i" > "$DIR"/"$FROM"/$i;
- git show "$TO":"$i" > "$DIR"/"$TO"/$i;
- done
- # Use git's difftool or opendiff as alternative
- DIFFTOOL=$(expr "$(git config --get diff.tool)" '|' "opendiff")
- $($DIFFTOOL "$DIR"/"$FROM" "$DIR"/"$TO")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement