-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbigtop-format-patch.sh
executable file
·60 lines (52 loc) · 1.09 KB
/
bigtop-format-patch.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
#!/bin/bash
# create a patch following bigtop workflow
# https://cwiki.apache.org/confluence/display/BIGTOP/How+to+Contribute
# directory where to save the patch
PATCH_DIR=~/tvorba/patch
show_help()
{
echo "$(basename $0): create a bigtop patch"
}
die()
{
echo "error: $1" 1>&2
exit 1
}
get_patch_name()
{
local BIGTOP_JIRA=$1
NAME_BASE=${PATCH_DIR}/${BIGTOP_JIRA}
N=1
while [[ -e "${NAME_BASE}.${N}.patch" ]]; do
: $((N++))
done
echo "${NAME_BASE}.${N}.patch"
}
make_patch()
{
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ ${GIT_BRANCH} =~ ^local_(BIGTOP-[0-9]+).*$ ]]; then
BIGTOP_JIRA=${BASH_REMATCH[1]}
else
die "name of current branch doesn't follow regexp local_BIGTOP-[0-9]+"
fi
PATCH_NAME=$(get_patch_name ${BIGTOP_JIRA})
GIT_FORMAT_PATCH="git format-patch HEAD^..HEAD --stdout"
if [[ $DEBUG ]]; then
echo $GIT_FORMAT_PATCH \> ${PATCH_NAME}
else
$GIT_FORMAT_PATCH > ${PATCH_NAME}
fi
}
#
# main
#
# debug mode
if [[ $1 = "-d" ]]; then
DEBUG=echo
shift
fi
case $1 in
-h|--help|help) show_help;;
*) make_patch;;
esac