Skip to content

Commit 21175b4

Browse files
chippersX1011
authored andcommitted
add support for custom commit messages
this includes flags -m and --message for setting the text, and the ability to disable appending the hash with flags -n or --no-hash closes #13
1 parent 2342d98 commit 21175b4

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

deploy.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ main() {
1212
#repository to deploy to. must be readable and writable.
1313
repo=${GIT_DEPLOY_REPO:-origin}
1414

15+
#append commit hash to the end of message by default
16+
append_hash=true
17+
1518
# Parse arg flags
1619
while : ; do
1720
if [[ $1 = "-v" || $1 = "--verbose" ]]; then
@@ -20,6 +23,12 @@ main() {
2023
elif [[ $1 = "-e" || $1 = "--allow-empty" ]]; then
2124
allow_empty=true
2225
shift
26+
elif [[ ( $1 = "-m" || $1 = "--message" ) && -n $2 ]]; then
27+
commit_message=$2
28+
shift 2
29+
elif [[ $1 = "-n" || $1 = "--no-hash" ]]; then
30+
append_hash=false
31+
shift
2332
else
2433
break
2534
fi
@@ -34,6 +43,17 @@ main() {
3443

3544
commit_title=`git log -n 1 --format="%s" HEAD`
3645
commit_hash=` git log -n 1 --format="%H" HEAD`
46+
47+
#default commit message uses last title if a custom one is not supplied
48+
if [[ -z $commit_message ]]; then
49+
commit_message="publish: $commit_title"
50+
fi
51+
52+
#append hash to commit message unless no hash flag was found
53+
if [ $append_hash = true ]; then
54+
commit_message="$commit_message"$'\n\n'"generated from commit $commit_hash"
55+
fi
56+
3757
previous_branch=`git rev-parse --abbrev-ref HEAD`
3858

3959
if [ ! -d "$deploy_directory" ]; then
@@ -91,8 +111,7 @@ incremental_deploy() {
91111

92112
commit+push() {
93113
set_user_id
94-
git --work-tree "$deploy_directory" commit -m \
95-
"publish: $commit_title"$'\n\n'"generated from commit $commit_hash"
114+
git --work-tree "$deploy_directory" commit -m "$commit_message"
96115

97116
disable_expanded_output
98117
#--quiet is important here to avoid outputting the repo URL, which may contain a secret token

0 commit comments

Comments
 (0)