forked from cmcculloh/GitScripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gitdifftool.sh
executable file
·72 lines (61 loc) · 1.49 KB
/
gitdifftool.sh
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
#!/bin/bash
## /*
# @usage gitdiff [base-branch-name]
#
# @description
# This script is used to get a quick look at all the files that have been added,
# modified, and/or deleted in the current branch's latest commit and either a
# specified branch (the first parameter) or the master branch (default).
# description@
#
# @notes
# - If your project does not have a master branch, you will need to pass the first
# parameter for each use.
# notes@
#
# @examples
# 1) gitdiff stage # Shows file changes between the stage branch and HEAD
# examples@
#
# @dependencies
# functions/5000.branch_exists.sh
# dependencies@
#
# @file gitdiff.sh
## */
$loadfuncs
echo
branch="master"
if [ -n "$1" ]; then
branch=$1
fi
# make sure branch exists
if ! __branch_exists "$branch"; then
echo ${E}" Branch \`$branch\` does not exist! Aborting... "${X}
exit 1
fi
# get 7 digit shortened hash for each commit
hashFrom=$(git rev-parse --short $branch)
hashTo=$(git rev-parse --short HEAD)
echo ${O}${H2HL}
echo "$ git diff --name-status $hashFrom..$hashTo"
echo
echo "git diff --name-status ${hashFrom}..${hashTo}"
if [ $SYSTEM_TYPE == "windows" ]; then
git diff --name-status $hashFrom..$hashTo
else
while read STATUS ADDR
do
echo " # $ADDR ($STATUS)"
done < <(git diff --name-status ${hashFrom}..${hashTo})
fi
echo
echo "git difftool -w $hashFrom..$hashTo"
echo ${H2HL}${X}
echo
echo ${Q}"Do diff? y (n)"${X}
read yn
if [ "$yn" = "y" ] || [ "$yn" = "Y" ]; then
git difftool -w $hashFrom..$hashTo
fi
exit