-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitvimdiff
More file actions
executable file
·103 lines (96 loc) · 2.33 KB
/
gitvimdiff
File metadata and controls
executable file
·103 lines (96 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
#
# Copyright (C) 2010,
# Thomas Langewouters <[email protected]>
# Based on the script svnvimdiff, written by
# Copyright (C) 2007,
# Geoff Buchan <[email protected]>
# Based on the script cvsvimdiff, written by
# Stefano Zacchiroli <[email protected]>
# Enrico Tassi <[email protected]>
#
# This is free software, you can redistribute it and/or modify it under the
# terms of the GNU General Public License version 2 as published by the Free
# Software Foundation.
#
set -ex
vimdiff="vimdiff"
#suffix="vimgitdiff"
if [[ $1 == "-g" ]] ; then
vimdiff="gvimdiff -f"
shift 1
fi
if [[ $# -lt 0 || $1 == "--help" || $1 == "-h" ]] ; then
echo "gitvimdiff - script to show git diff in vimdiff format in tabs"
echo ""
echo "gitvimdiff [options] file"
echo ""
echo "Option:"
echo "-g Use gvimdiff (graphical mode) instead of vimdiff"
echo "All other options are passed to git diff"
echo ""
echo "If file is omitted it will cycle through all changed files in"
echo "the current directory."
exit 1
fi
# Assume the last argument is the filename.
# Save everything to pass to svn diff
if (( $# > 0 )) ; then
shift_args=$(($# - 1))
else
shift_args=$#
fi
TMP=$(mktemp -d /tmp/gitvimdiff.XXXX)
args=$*
shift "$shift_args"
files="$1"
#patch=$TMP/patch
script=$TMP/script
GITROOT=$(dirname $1)
while [[ ! -e $GITROOT/.git ]]
do
GITROOT=$(dirname "$GITROOT")
if [ "$GITROOT" = "/" ]
then
break
fi
done
if [ "$GITROOT" = "/" ]
then
echo gitroot not found! >/dev/stderr
exit 0
fi
if [ -n "$files" ]
then
echo $files
files=${files#"${GITROOT}/"}
echo $files
fi
cd "$GITROOT"
# No file given, so loop over all files svn st says have changed
if [ -z "$args" ]; then
files=$(git diff --name-only)
else
files=$(git diff --name-only "$files")
fi
echo "Changed files: $files"
if [ -z "$files" ] ; then
echo "No changes to show"
exit 1
fi
for new in $files
do
#Instead of [ -z $(foo | grep bar) ], use ! foo | grep -q bar . [SC2143]
if ! file "$new" |grep -q text;
then
#binary file
true
else
orig=$TMP/$new
mkdir -p "$(dirname "$orig")"
git show HEAD:"$new" >"$orig"
echo -e ":tabnew $orig\n:vert diffsplit $new" >> "$script"
fi
done
$vimdiff -s "$script" commit.txt
#trap "rm -rf $TMP" EXIT