-
Notifications
You must be signed in to change notification settings - Fork 5
Add Linux support, Add local file support #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
f0b5a3b
e297085
a99d73d
b78bd34
8c04b33
e72ebc7
c7b88f1
87987c0
71f695d
469a85c
9d9312e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,12 +1,17 @@ | ||||||
| #!/bin/sh | ||||||
| #!/bin/bash | ||||||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason for the switch to
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe @schnappfuesch can help 😊 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The If you pipe the script into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A more portable solution would be
Suggested change
which works on all systems (including the more obscure ones like NixOS, where |
||||||
|
|
||||||
| should_use_file_from_github_url=true | ||||||
| # defaults | ||||||
| PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER="^\s*\[[\-\w]*\d\]" | ||||||
| PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER_ONE="^\s*\[[\-\w]*\d\]" | ||||||
| PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER_TWO="^\s*[\-\w]*\d:" | ||||||
| PLACEHOLDER_REGEX_BRANCH_ISSUE_NUMBER="[.]*\/([\-\w]*?\-\d+)" | ||||||
| PLACEHOLDER_REGEX_GIT_COMMIT_MESSAGES="(Merge\sbranch\s\'|\#\sRebase\s|This\sreverts\scommit\s)" | ||||||
| PLACEHOLDER_LOGGING_VERBOSE="true" | ||||||
|
|
||||||
| GITHUB_SCRIPT_URL="https://raw.githubusercontent.com/janniks/prepare-commit-msg/master/scripts/prepare-commit-msg" | ||||||
| PLACEHOLDER_NEW_COMMIT_MESSAGE="[#{issue_number.upcase}] #{original_commit_message.gsub(/(\s[[:punct:]])+$/, '')}" | ||||||
| PLACEHOLDER_NEW_COMMIT_MESSAGE_ONE="[#{issue_number.upcase}] #{original_commit_message.gsub(/(\s[[:punct:]])+$/, '')}" | ||||||
| PLACEHOLDER_NEW_COMMIT_MESSAGE_TWO="#{issue_number.upcase}: #{original_commit_message.gsub(/(\s[[:punct:]])+$/, '')}" | ||||||
| GITHUB_SCRIPT_URL="https://raw.githubusercontent.com/yrave/prepare-commit-msg/master/scripts/prepare-commit-msg" | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| PATH_GIT_GLOBAL="${HOME}/.git-template/" | ||||||
| PATH_GIT_LOCAL="./.git/" | ||||||
|
|
@@ -75,16 +80,50 @@ if [ "$answer" != "${answer#[Yy]}" ]; then | |||||
| PLACEHOLDER_LOGGING_VERBOSE=false | ||||||
| fi | ||||||
|
|
||||||
| printf -- "Set a custom regex for parsing issue numbers from commit messages:\n" | ||||||
| printf -- " - To use default value, leave empty and press return\n\n" | ||||||
| printf -- "Default: ${BLUE}${PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER}${RESET}\n${BLUE}>${RESET} " | ||||||
| printf -- "Set a custom message style where ISSUE_NUMBER is the issue number and COMMIT_MESSAGE is the commit message.\n" | ||||||
| printf -- " - To use default value, leave empty and press return\n" | ||||||
| printf -- "Default: ${BLUE}${PLACEHOLDER_NEW_COMMIT_MESSAGE}${RESET}\n\n" | ||||||
| printf -- " - To use ${GREEN}[ISSUE_NUMBER] COMMIT_MESSAGE${RESET}, enter 1\n" | ||||||
| printf -- "1: ${BLUE}${PLACEHOLDER_NEW_COMMIT_MESSAGE_ONE}${RESET}\n\n" | ||||||
| printf -- " - To use ${GREEN}ISSUE_NUMBER: COMMIT_MESSAGE${RESET}, enter 2\n" | ||||||
| printf -- "2: ${BLUE}${PLACEHOLDER_NEW_COMMIT_MESSAGE_TWO}${RESET}\n\n${BLUE}>${RESET} " | ||||||
| read answer | ||||||
|
|
||||||
| if [ ! -z "$answer" ]; then | ||||||
| PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER=answer | ||||||
| if [ "$answer" == "1" ]; then | ||||||
| PLACEHOLDER_NEW_COMMIT_MESSAGE=$PLACEHOLDER_NEW_COMMIT_MESSAGE_ONE | ||||||
| elif [ "$answer" == "2" ]; then | ||||||
| PLACEHOLDER_NEW_COMMIT_MESSAGE=$PLACEHOLDER_NEW_COMMIT_MESSAGE_TWO | ||||||
| else | ||||||
| PLACEHOLDER_NEW_COMMIT_MESSAGE=answer | ||||||
| fi | ||||||
| fi | ||||||
|
|
||||||
| clear_n_lines 5 | ||||||
| clear_n_lines 12 | ||||||
| printf -- " - ${BLUE}Commit message style: ${PLACEHOLDER_NEW_COMMIT_MESSAGE} ${RESET}\n\n" | ||||||
|
|
||||||
| printf -- "Set a custom regex for parsing issue numbers from commit messages:\n\n" | ||||||
| printf -- " - To use default value, leave empty and press return\n" | ||||||
| printf -- "Default: ${BLUE}${PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER}${RESET}\n\n" | ||||||
| printf -- " - To use ${GREEN}[ISSUE_NUMBER] COMMIT_MESSAGE${RESET}, enter 1\n" | ||||||
| printf -- "1: ${BLUE}${PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER_ONE}${RESET}\n\n" | ||||||
| printf -- " - To use ${GREEN}ISSUE_NUMBER: COMMIT_MESSAGE${RESET}, enter 2\n" | ||||||
| printf -- "2: ${BLUE}${PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER_TWO}${RESET}\n\n${BLUE}>${RESET} " | ||||||
| read answer | ||||||
|
|
||||||
| if [ ! -z "$answer" ]; then | ||||||
| if [ "$answer" == "1" ]; then | ||||||
| PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER=$PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER_ONE | ||||||
| elif [ "$answer" == "2" ]; then | ||||||
| PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER=$PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER_TWO | ||||||
| else | ||||||
| PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER=answer | ||||||
| fi | ||||||
| fi | ||||||
|
|
||||||
| clear_n_lines 13 | ||||||
| printf -- " - ${BLUE}Regex for commit message: ${PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER} ${RESET}\n\n" | ||||||
|
|
||||||
| printf -- "Set a custom regex for parsing issue numbers from branch names:\n" | ||||||
| printf -- " - To use default value, leave empty and press return\n\n" | ||||||
| printf -- "Default: ${BLUE}${PLACEHOLDER_REGEX_BRANCH_ISSUE_NUMBER}${RESET}\n${BLUE}>${RESET} " | ||||||
|
|
@@ -125,7 +164,7 @@ if [ "$OPTION_GLOBAL_TEMPLATE" = true ]; then | |||||
| printf -- " - A global \'${BLUE}${HOOK_NAME}${RESET}\' git hook already exists. ${RED}Aborting...${RESET}\n\n" | ||||||
| exit | ||||||
| fi | ||||||
|
|
||||||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👾 |
||||||
| HOOK_FILE="${PATH_GIT_GLOBAL}${HOOK_DIR}${HOOK_NAME}" | ||||||
|
|
||||||
| printf -- " - Setting global git-template...\n" | ||||||
|
|
@@ -140,8 +179,14 @@ else | |||||
| HOOK_FILE="${PATH_GIT_LOCAL}${HOOK_DIR}${HOOK_NAME}" | ||||||
| fi | ||||||
|
|
||||||
| printf -- " - Downloading git hook...\n" | ||||||
| curl -s "$GITHUB_SCRIPT_URL" > "$HOOK_FILE" | ||||||
| if [ "$should_use_file_from_github_url" = true ] ; then | ||||||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also a very nice feature 🙌 I might also like to add this to the install script There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks :) I was too lazy to add it to the advanced option and I used it only for testing |
||||||
| printf -- " - Downloading git hook...\n" | ||||||
| curl -s "$GITHUB_SCRIPT_URL" > "$HOOK_FILE" | ||||||
| else | ||||||
| printf -- " - Creating git hook file from local file\n" | ||||||
| BASEDIR=$(dirname $0) | ||||||
| cat "${BASEDIR}/prepare-commit-msg" > "$HOOK_FILE" | ||||||
| fi | ||||||
|
|
||||||
| printf -- " - Replacing placeholders...\n" | ||||||
| PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER=$(printf -- "$PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER" | sed 's/\\/\\\\/g') | ||||||
|
|
@@ -153,11 +198,22 @@ PLACEHOLDER_REGEX_BRANCH_ISSUE_NUMBER=$(printf -- "$PLACEHOLDER_REGEX_BRANCH_ISS | |||||
| PLACEHOLDER_REGEX_GIT_COMMIT_MESSAGES=$(printf -- "$PLACEHOLDER_REGEX_GIT_COMMIT_MESSAGES" | sed 's/\\/\\\\/g') | ||||||
| printf -v PLACEHOLDER_REGEX_GIT_COMMIT_MESSAGES "%q" "$PLACEHOLDER_REGEX_GIT_COMMIT_MESSAGES" | ||||||
| PLACEHOLDER_REGEX_GIT_COMMIT_MESSAGES=$(printf -- "$PLACEHOLDER_REGEX_GIT_COMMIT_MESSAGES" | sed 's/\//\\\//g') | ||||||
| PLACEHOLDER_NEW_COMMIT_MESSAGE=$(printf -- "$PLACEHOLDER_NEW_COMMIT_MESSAGE" | sed 's/\//\\\//g') | ||||||
|
|
||||||
| replace_placeholder_with_value () { | ||||||
| if [ $(uname -s) == "Linux" ]; then | ||||||
| sed -i "s/${1}/${2}/g" "$HOOK_FILE" | ||||||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! Is this important/relevant for all Linux? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’ve worked on other scripts that use the sed command and it’s been relevant for all Linux user. |
||||||
| return | ||||||
| fi | ||||||
|
|
||||||
| sed -i '' "s/${1}/${2}/g" "$HOOK_FILE" | ||||||
| } | ||||||
|
|
||||||
| sed -i '' "s/PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER/\/${PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER}\//g" "$HOOK_FILE" | ||||||
| sed -i '' "s/PLACEHOLDER_REGEX_BRANCH_ISSUE_NUMBER/\/${PLACEHOLDER_REGEX_BRANCH_ISSUE_NUMBER}\//g" "$HOOK_FILE" | ||||||
| sed -i '' "s/PLACEHOLDER_REGEX_GIT_COMMIT_MESSAGES/\/${PLACEHOLDER_REGEX_GIT_COMMIT_MESSAGES}\//g" "$HOOK_FILE" | ||||||
| sed -i '' "s/PLACEHOLDER_LOGGING_VERBOSE/${PLACEHOLDER_LOGGING_VERBOSE}/g" "$HOOK_FILE" | ||||||
| replace_placeholder_with_value PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER "\/${PLACEHOLDER_REGEX_COMMIT_ISSUE_NUMBER}\/" | ||||||
| replace_placeholder_with_value PLACEHOLDER_REGEX_BRANCH_ISSUE_NUMBER "\/${PLACEHOLDER_REGEX_BRANCH_ISSUE_NUMBER}\/" | ||||||
| replace_placeholder_with_value PLACEHOLDER_REGEX_GIT_COMMIT_MESSAGES "\/${PLACEHOLDER_REGEX_GIT_COMMIT_MESSAGES}\/" | ||||||
| replace_placeholder_with_value PLACEHOLDER_LOGGING_VERBOSE "${PLACEHOLDER_LOGGING_VERBOSE}" | ||||||
| replace_placeholder_with_value PLACEHOLDER_NEW_COMMIT_MESSAGE "${PLACEHOLDER_NEW_COMMIT_MESSAGE}" | ||||||
|
|
||||||
| printf -- " - Requesting permission to execute git hook...\n" | ||||||
| chmod a+x "$HOOK_FILE" | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced in PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.