forked from OpenCPN/OpenCPN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-pr
executable file
·61 lines (49 loc) · 1.36 KB
/
check-pr
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
#!/bin/bash
#
# Check an OpenCPN pull request for whitespace errors.
#
function usage() {
cat << EOT
Usage:
check-pr [-l | -h] <<PR url> | <Repo url> <branch>>
Parameters:
PR url:
As copied from the Github UI, something like
https://github.com/Github6am/OpenCPN/tree/opti_amerz
Repo url:
As of the Github UI, the Code button; something like
https://github.com/Github6am/OpenCPN
Options:
-l Print a list of offending files rather than the complete diff.
-h Print this help message and exit
EOT
}
# Handle options and parameters
if [ "$1" = "-h" ]; then usage; exit 0; fi
if [ "$1" = "-l" ]; then list_opt='true'; shift; fi
if [ $# -eq 1 ]; then
url=${1%%OpenCPN/*}/OpenCPN
branch=${1##*/tree/}
elif [ $# -eq 2 ]; then
url=$1
branch=$2
else
usage >&1
exit 1
fi
# Set up the pr-tmp remote and the empty tree we compare against
if git config remote.pr-tmp.url >/dev/null; then
git remote remove pr-tmp
fi
git remote add pr-tmp $url
git fetch pr-tmp $branch
empty_tree=$(git hash-object -t tree /dev/null)
# Do the check
if [ -n "$list_opt" ]; then
exec > >(sed -e 's/:.*//' -e '/^+/d' | uniq)
fi
for f in $(git diff --name-only --diff-filter=ACMR HEAD pr-tmp/$branch); do
git diff-tree --check $empty_tree pr-tmp/$branch $f
done
# Cleanup (stdout possibly redirected).
git remote remove pr-tmp