-
-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathgit-modified-since
executable file
·53 lines (46 loc) · 1.13 KB
/
git-modified-since
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
#!/bin/sh
set -e
usage () {
echo "usage: git modified-since [-iuqh] [<commit>]" >&2
echo >&2
echo "Prints list of files that have been modified since the given branch." >&2
echo "Defaults to the repo's default branch." >&2
echo "" >&2
echo "This script is ideal for passing all locally modified files into your editor, like:" >&2
echo ' $ vim `git modified-since`' >&2
echo >&2
echo "Options:" >&2
echo "-q Be quiet, only return with 0 exit code when files are modified" >&2
echo "-h Show this help" >&2
}
quiet=0
while getopts qh flag; do
case "$flag" in
q) quiet=1;;
h) usage; exit 2;;
esac
done
shift $(($OPTIND - 1))
commit="$(git main-branch)"
if [ $# -ge 1 ]; then
commit="$1"
fi
make_relative () {
while read f; do
git relative-path "$f"
done
}
get_changed_files () {
git diff --stat --name-only "$commit"... -- | make_relative
}
fail_if_empty () {
empty=1
while read line; do
if [ $quiet -eq 0 ]; then
echo "$line"
fi
empty=0
done
test $empty -eq 0
}
get_changed_files | fail_if_empty