Created
December 12, 2009 20:16
-
-
Save husio/255033 to your computer and use it in GitHub Desktop.
Git diff for branches using vimdiff
This file contains 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
#!/usr/bin/env bash | |
function show_help_and_exit { | |
echo -e "Usage\n\t$1 <master branch> <branch to merge>\n" | |
exit 2 | |
} | |
[[ $# -eq 2 ]] || show_help_and_exit | |
VIMDIFF=vimdiff | |
MASTER_BRANCH=$1 | |
MERGE_FROM_BRANCH=$2 | |
TEMP_DIR="/tmp/gitvimdiff" | |
TEMP_FILE="$TEMP_DIR/`date '+%H:%M:%S.%N'`" | |
MASTER_FILE="$TEMP_FILE.master" | |
TO_MERGE_FILE="$TEMP_FILE.to_merge" | |
CHANGED_FILES="`git diff "$MASTER_BRANCH" "$MERGE_FROM_BRANCH" --name-only`" | |
function cleanup_data { | |
echo 'cleaning temporary directory..' | |
rm -rf $TEMP_DIR | |
} | |
function bashtrap { | |
cleanup_data | |
} | |
trap bashtrap INT | |
mkdir -p $TEMP_DIR 2> /dev/null | |
git checkout $MERGE_FROM_BRANCH &> /dev/null || exit 4 | |
for file in $CHANGED_FILES | |
do | |
echo -e "++++ $file ++++" >> $TO_MERGE_FILE | |
if [[ -f $file ]] | |
then | |
cat $file >> $TO_MERGE_FILE | |
fi | |
done | |
git checkout $MASTER_BRANCH &> /dev/null || exit 5 | |
for file in $CHANGED_FILES | |
do | |
echo -e "---- $file ----" >> $MASTER_FILE | |
if [[ -f $file ]] | |
then | |
cat $file >> $MASTER_FILE | |
fi | |
done | |
$VIMDIFF $MASTER_FILE $TO_MERGE_FILE | |
cleanup_data | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment