-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtcrdd.sh
executable file
·94 lines (78 loc) · 1.54 KB
/
tcrdd.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
BRANCH=origin/master
TEST_KEYWORD="@Test"
function runTest() {
./gradlew test
}
function testJustAdded(){
[[ ! -z `git diff HEAD | grep "^\+.*${TEST_KEYWORD}"` ]]
}
RED_REF=refs/isRed
function commitRed() {
git add . && \
if lastCommitRed; then
git commit --amend
else
git commit
fi && \
git update-ref ${RED_REF} HEAD
}
function commitGreen() {
git add . && \
if lastCommitRed; then
git commit --amend --no-edit
else
git commit --allow-empty-message -m ""
fi && \
git update-ref -d ${RED_REF}
}
function lastCommitRed(){
[[ `git describe --all ${RED_REF} 2>/dev/null` && -z `git diff ${RED_REF} HEAD 2>/dev/null` ]]
}
function revert() {
git reset --hard
git clean -f
}
function pull(){
if needsPull; then
git pull --rebase
fi
}
function needsPull(){
[[ ! -z `git fetch --dry-run 2>&1` ]]
}
function push() {
if needsPush; then
runTest && git push
fi
}
function needsPush(){
[[ ! -z `git diff ${BRANCH} HEAD` ]]
}
KNOWN_AS_GREEN=false
KNOWN_AS_RED=false
while [[ $# -gt 0 ]]
do
key="$1"
case ${key} in
-g|--green)
KNOWN_AS_GREEN=true
shift
;;
-r|--red)
KNOWN_AS_RED=true
shift
;;
*)
shift
;;
esac
done
if ${KNOWN_AS_RED} || (! ${KNOWN_AS_GREEN} && testJustAdded)
then
runTest && revert || commitRed
pull
else
runTest && commitGreen || revert
pull && push
fi