-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit
More file actions
executable file
·104 lines (92 loc) · 2.66 KB
/
commit
File metadata and controls
executable file
·104 lines (92 loc) · 2.66 KB
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
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
BRANCH_NAME=`git symbolic-ref --short HEAD`
TAG_OPTIONS=("Fix" "Update" "New" "Breaking" "Docs" "Build" "Upgrade" "Chore")
COMMIT_TAG=""
MESSAGE=""
DESCRIPTION=""
Help ()
{
echo "Format your commit message as below:"
echo " branch_name [commit_tag]: commit message"
echo
echo "Syntax: scriptTemplate [-d|h|m|t]"
echo "OPTIONS:"
echo "h Print this help"
echo "t Commit Tags "
echo " Commit Tags Options:"
echo " Fix for a bug fix. "
echo " Update either for a backwards-compatible enhancement or for a rule change that adds reported problems. "
echo " New implemented a new feature."
echo " Breaking for a backwards-incompatible enhancement or feature."
echo " Docs changes to documentation only."
echo " Build changes to build process only."
echo " Upgrade for a dependency upgrade."
echo " Chore for refactoring, adding tests, etc. (anything that isn't user-facing)."
echo "m Commit Message"
echo "d Description for commit message [optional]"
echo
echo "Command:"
echo " commit -t \"Docs\" -m \"Add README file\""
echo " commit -t \"Docs\" -m \"Add README file\" -d \"Add Project Setup Guideline for local environment\""
echo
echo "Commit Message Output:"
echo " main [Docs]: Add README file"
echo
echo
}
if [[ $1 = "-h" || $1 = "--help" ]]; then
Help
exit;
fi
# Get Options
while getopts ":t:m:d:" option; do
case $option in
t)
COMMIT_TAG=$OPTARG
;;
m)
MESSAGE=$OPTARG
;;
d)
DESCRIPTION=$OPTARG
;;
\?)
echo "ERROR: Unknown option -$OPTARG" 1>&2
exit
;;
esac
done
if ((OPTIND == 1))
then
echo "ERROR: No options specified"
exit;
fi
shift $((OPTIND -1))
if [[ -z "${COMMIT_TAG}" ]]
then
echo "ERROR: Please add commit tag."
echo "Options: Fix | Update | New | Breaking | Docs | Build | Upgrade | Chore"
exit;
else
if [[ ! "${TAG_OPTIONS[*]}" =~ "${COMMIT_TAG}" ]]; then
echo "ERROR: Invalid commit tag."
echo "Options: Fix | Update | New | Breaking | Docs | Build | Upgrade | Chore"
exit;
fi
fi
if [[ -z "${MESSAGE}" ]]; then
echo "ERROR: Please add commit message"
exit;
fi
COMMIT_MESSAGE="$BRANCH_NAME [$COMMIT_TAG]: $MESSAGE"
git commit -m "$COMMIT_MESSAGE" -m "$DESCRIPTION"
if [ $? -ne 0 ]; then
exit;
fi
LOG_DIRECTORY="$HOME/work_log"
if [ ! -d $LOG_DIRECTORY ];
then
mkdir $LOG_DIRECTORY
fi
FILENAME="$(date +%F).log"
echo $COMMIT_MESSAGE >> "$LOG_DIRECTORY/$FILENAME"