-
Notifications
You must be signed in to change notification settings - Fork 16
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
iox-#2 Add git hooks #72
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Git Hooks for iceoryx-rs | ||
|
||
The provided hooks add the github issue number to the commit message | ||
and check for trailing whitespaces and code style violations with `cargo fmt`. | ||
|
||
## Installation | ||
|
||
The hooks are active when you add the `git-hooks` directory as hooks folder to | ||
your local project git config: | ||
|
||
```bash | ||
git config core.hooksPath tools/git-hooks/ | ||
``` | ||
|
||
With that you will also receive the updates of the git hooks in the future. | ||
We recommend doing this in every new clone you did on iceoryx-rs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#! /bin/bash | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
# SPDX-FileCopyrightText: © Contributors to the iceoryx-rs project | ||
# SPDX-FileContributor: Mathias Kraus | ||
|
||
# This script checks for trailing whitespaces on the modified file and runs 'cargo fmt --check' | ||
|
||
set -eu | ||
|
||
COLOR_OFF='\033[0m' | ||
COLOR_RED='\033[1;31m' | ||
COLOR_GREEN='\033[1;32m' | ||
COLOR_YELLOW='\033[1;33m' | ||
|
||
# check for trailing whitespaces | ||
NUMBER_OF_FILES_WITH_TRAILING_WHITESPACES=0 | ||
for FILE in $(git diff --name-only --staged --diff-filter=ACMRT) ; do | ||
if [[ -f ${FILE} ]]; then | ||
LINES_WITH_WHITESPACES=$(egrep -no '[[:space:]]+$' ${FILE} | sed "s/://g") | ||
if [[ -n ${LINES_WITH_WHITESPACES} ]]; then | ||
if [[ ${NUMBER_OF_FILES_WITH_TRAILING_WHITESPACES} -eq 0 ]]; then | ||
echo -e "${COLOR_YELLOW}The following file(s) have line(s) with trailing whitespaces!${COLOR_OFF}" | ||
NUMBER_OF_FILES_WITH_TRAILING_WHITESPACES=${NUMBER_OF_FILES_WITH_TRAILING_WHITESPACES}+1 | ||
fi | ||
echo -e "${FILE} on line(s):" | ||
for LINE in ${LINES_WITH_WHITESPACES} ; do | ||
echo -e " ${LINE}" | ||
done | ||
fi | ||
fi | ||
done | ||
|
||
if [[ ${NUMBER_OF_FILES_WITH_TRAILING_WHITESPACES} -ne 0 ]]; then | ||
echo -e "${COLOR_YELLOW}Please remove the whitespaces and commit the changes with 'git commit --amend --no-edit'${COLOR_OFF}" | ||
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. Me like colors |
||
echo -e "" | ||
fi | ||
|
||
# check for cargo fmt | ||
if ! &>/dev/null cargo fmt -- --check | ||
then | ||
echo -e "${COLOR_YELLOW}The code is not formatted with 'cargo fmt'!${COLOR_OFF}" | ||
echo -e "${COLOR_YELLOW}Please run 'cargo fmt' and commit the changes with 'git commit --amend --no-edit'${COLOR_OFF}" | ||
echo -e "" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#! /bin/bash | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
# SPDX-FileCopyrightText: © 2021 - 2022 by Apex.AI Inc. All rights reserved. | ||
# SPDX-FileCopyrightText: © Contributors to the iceoryx-rs project | ||
# SPDX-FileContributor: Mathias Kraus | ||
|
||
# This script adds the issue number of the branch name to the commit message if it is available | ||
|
||
set -eu | ||
|
||
COLOR_RESET='\033[0m' | ||
COLOR_RED='\033[1;31m' | ||
COLOR_GREEN='\033[1;32m' | ||
COLOR_YELLOW='\033[1;33m' | ||
|
||
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) | ||
BRANCH_ISSUE_NUMBER='0' | ||
|
||
if [[ "${BRANCH_NAME}" =~ ^iox-[0-9]+ ]]; then | ||
BRANCH_ISSUE_NUMBER="$(echo "${BRANCH_NAME}" | grep -Eo 'iox-[0-9]+' | grep -Eo '[0-9]+')" | ||
else | ||
echo -e "${COLOR_YELLOW}" | ||
echo -e "Warning: The branch name doesn't follow the convention of 'iox-ISSUE_NUMBER'." | ||
echo -e "Commit message won't be autoformatted." | ||
echo -e "${COLOR_RESET}" | ||
exit 0 | ||
fi | ||
|
||
COMMIT_MSG=$(cat $1) | ||
if [[ ${COMMIT_MSG} =~ ^iox-#[0-9]+ ]]; then | ||
COMMIT_ISSUE_NUMBER="$(echo "${COMMIT_MSG}" | grep -Eo 'iox-#[0-9]+' | grep -Eo '[0-9]+')" | ||
if [[ "${COMMIT_ISSUE_NUMBER}" != "${BRANCH_ISSUE_NUMBER}" ]]; then | ||
echo -e "${COLOR_YELLOW}" | ||
echo -e "Warning: Commit message issue number does not fit to branch issue number: '${BRANCH_ISSUE_NUMBER}'" | ||
echo -e "Is this on purpose?" | ||
echo -e "Commit message will not be autoformatted." | ||
echo -e "${COLOR_RESET}" | ||
exit 0 | ||
fi | ||
else | ||
echo -e "${COLOR_GREEN}" | ||
echo -e "Info: Commit message does not start with issue number: '${COMMIT_MSG}'" | ||
echo -e "Commit message will be autoformatted." | ||
echo -e "${COLOR_RESET}" | ||
echo -e "iox-#${BRANCH_ISSUE_NUMBER} ${COMMIT_MSG}" > $1 | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What does this little thing do?
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.
The location. In my case European Union. It's
us
if you want to use the script from the United States ;)