Repository navigation
chore: add local DCO sign-off check #1359
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
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a0e31c1
FOU-1168: Add automatic commit sign-off hook
gjermundgaraba 39f0788
chore: add license header to commit hook
gjermundgaraba 18c85e1
chore: validate DCO sign-off locally
gjermundgaraba 30b8616
fix: align local DCO check with Git
gjermundgaraba 62b2ef9
fix: align local DCO hook with repository policy
gjermundgaraba aa94cdc
fix: preserve LF endings for Git hooks
gjermundgaraba 564012b
test: isolate DCO hook test from global hooks
gjermundgaraba 902bc5a
Merge branch 'main' into gjermund/fou-1168-commit-signoff-hook
gjermundgaraba e1afb60
docs: simplify DCO hook installation
gjermundgaraba 75228f9
docs: support worktrees when installing DCO hook
gjermundgaraba e24958a
Merge branch 'main' into gjermund/fou-1168-commit-signoff-hook
gjermundgaraba 1eef7e9
Merge branch 'main' into gjermund/fou-1168-commit-signoff-hook
gjermundgaraba 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 hidden or 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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| .githooks/* text eol=lf | ||
| *.pdf filter=lfs diff=lfs merge=lfs -text | ||
| *.png filter=lfs diff=lfs merge=lfs -text | ||
| *.jpg filter=lfs diff=lfs merge=lfs -text |
This file contains hidden or 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,21 @@ | ||
| #!/bin/sh | ||
|
|
||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| set -eu | ||
|
|
||
| git rev-parse -q --verify MERGE_HEAD >/dev/null 2>&1 && exit 0 | ||
|
|
||
| author=$(git var GIT_AUTHOR_IDENT) | ||
| author=${author% *} | ||
| author=${author% *} | ||
|
|
||
| committer=$(git var GIT_COMMITTER_IDENT) | ||
| committer=${committer% *} | ||
| committer=${committer% *} | ||
|
|
||
| git -c trailer.separators=: interpret-trailers --parse --no-divider "$1" | | ||
| grep -iFqx -e "Signed-off-by: $author" -e "Signed-off-by: $committer" && exit 0 | ||
|
|
||
| printf >&2 'Missing DCO sign-off. Re-run your commit command with --signoff.\n' | ||
| exit 1 |
This file contains hidden or 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,49 @@ | ||
| #!/bin/sh | ||
|
|
||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| set -eu | ||
|
|
||
| hook=$(dirname "$0")/commit-msg | ||
| message=$(mktemp) | ||
| repository=$(mktemp -d) | ||
| trap 'rm -f "$message"; rm -rf "$repository"' EXIT | ||
|
|
||
| export GIT_COMMITTER_NAME='DCO Test' | ||
| export GIT_COMMITTER_EMAIL='dco@example.com' | ||
| export GIT_AUTHOR_NAME='DCO Author' | ||
| export GIT_AUTHOR_EMAIL='author@example.com' | ||
|
|
||
| printf 'Test\n\nSigned-off-by: DCO Test <dco@example.com>\n' >"$message" | ||
| "$hook" "$message" | ||
|
|
||
| printf 'Test\n\n---\n\nSigned-off-by: DCO Test <dco@example.com>\n' >"$message" | ||
| "$hook" "$message" | ||
|
|
||
| GIT_CONFIG_COUNT=1 \ | ||
| GIT_CONFIG_KEY_0=trailer.separators \ | ||
| GIT_CONFIG_VALUE_0='=' \ | ||
| "$hook" "$message" | ||
|
|
||
| printf 'Test\n\nSigned-off-by: DCO Author <author@example.com>\n' >"$message" | ||
| "$hook" "$message" | ||
|
|
||
| printf 'Test\n\nSigned-off-by: Someone Else <else@example.com>\n' >"$message" | ||
| if "$hook" "$message" 2>/dev/null; then | ||
| printf >&2 'Unrelated sign-off was accepted\n' | ||
| exit 1 | ||
| fi | ||
|
|
||
| printf 'Test\n' >"$message" | ||
|
|
||
| git init --quiet "$repository" | ||
| git -C "$repository" config user.name 'DCO Test' | ||
| git -C "$repository" config user.email 'dco@example.com' | ||
| git -C "$repository" -c commit.gpgsign=false -c core.hooksPath=/dev/null commit --allow-empty --quiet -m 'Test' | ||
| git -C "$repository" rev-parse HEAD >"$repository/.git/MERGE_HEAD" | ||
| GIT_DIR="$repository/.git" "$hook" "$message" | ||
|
|
||
| if "$hook" "$message" 2>/dev/null; then | ||
| printf >&2 'Unsigned commit message was accepted\n' | ||
| exit 1 | ||
| fi |
This file contains hidden or 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
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.