generated from devcontainers/feature-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement prepare-commit-msg-context feature
- Loading branch information
Showing
10 changed files
with
112 additions
and
4 deletions.
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
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,8 @@ | ||
{ | ||
"name": "prepare-commit-msg-context", | ||
"id": "prepare-commit-msg-context", | ||
"version": "1.0.0", | ||
"description": "Install a prepare-commit-msg hook script to /usr/local/share(the script writes the commit content as a comment).", | ||
"options": {}, | ||
"installsAfter": [] | ||
} |
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,9 @@ | ||
#!/usr/bin/env sh | ||
|
||
INSTALL_DIR="/usr/local/share/prepare-commit-msg-context" | ||
|
||
set -e | ||
|
||
test -d "${INSTALL_DIR}" || mkdir -p "${INSTALL_DIR}" | ||
cp "$(dirname "${0}")/prepare-commit-msg" "${INSTALL_DIR}/prepare-commit-msg" | ||
chmod a+x "${INSTALL_DIR}/prepare-commit-msg" |
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,18 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
COMMIT_MSG_FILE="${1}" | ||
COMMIT_SOURCE=$2 | ||
SHA1=$3 | ||
|
||
echo "" >> "${COMMIT_MSG_FILE}" | ||
git diff --cached | sed 's/^/# /' >> "${COMMIT_MSG_FILE}" | ||
|
||
case "$COMMIT_SOURCE,$SHA1" in | ||
,|template,) | ||
echo "" >> "${COMMIT_MSG_FILE}" | ||
echo "# Recent History" >> "${COMMIT_MSG_FILE}" | ||
git log --oneline --graph --decorate -n 10 | sed 's/^/# /' >> "${COMMIT_MSG_FILE}" ;; | ||
*) ;; | ||
esac |
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 @@ | ||
{} |
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,31 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Optional: Import test library bundled with the devcontainer CLI | ||
# Provides the 'check' and 'reportResults' commands. | ||
source dev-container-features-test-lib | ||
|
||
# Check for installed features | ||
check "Check prepare-commit-msg is installed" test -x /usr/local/share/prepare-commit-msg-context/prepare-commit-msg | ||
|
||
# Check for working features | ||
git config --global user.email "you@example.com" | ||
git config --global user.name "Your Name" | ||
git config --global init.defaultBranch main | ||
# Make temp repo | ||
TEMP_FILE=$(mktemp) | ||
TEMP_DIR=$(mktemp -d) | ||
pushd "${TEMP_DIR}" | ||
git init | ||
git commit --allow-empty -m "Initial commit" | ||
echo "test" > test.txt | ||
git add test.txt | ||
# Run prepare-commit-msg | ||
/usr/local/share/prepare-commit-msg-context/prepare-commit-msg "${TEMP_FILE}" | ||
popd | ||
check "Check prepare-commit-msg-context is working" diff <(sed -e 's/.\+ Initial commit/---/' < "${TEMP_FILE}") expected.txt | ||
|
||
# Report result | ||
# If any of the checks above exited with a non-zero exit code, the test will fail. | ||
reportResults |
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,11 @@ | ||
|
||
# diff --git a/test.txt b/test.txt | ||
# new file mode 100644 | ||
# index 0000000..9daeafb | ||
# --- /dev/null | ||
# +++ b/test.txt | ||
# @@ -0,0 +1 @@ | ||
# +test | ||
|
||
# Recent History | ||
--- |
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,15 @@ | ||
{ | ||
"basic": { | ||
"image": "mcr.microsoft.com/devcontainers/base:ubuntu", | ||
"features": { | ||
"ghcr.io/devcontainers/features/common-utils:1": { | ||
"installZsh": false, | ||
"installOhMyZsh": false, | ||
"upgradePackages": false, | ||
"username": "node" | ||
}, | ||
"prepare-commit-msg-context": {} | ||
}, | ||
"remoteUser": "node" | ||
} | ||
} |
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,15 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Optional: Import test library bundled with the devcontainer CLI | ||
# Provides the 'check' and 'reportResults' commands. | ||
source dev-container-features-test-lib | ||
|
||
# Feature-specific tests | ||
# The 'check' command comes from the dev-container-features-test-lib. | ||
check "Check prepare-commit-msg is installed" test -x /usr/local/share/prepare-commit-msg-context/prepare-commit-msg | ||
|
||
# Report result | ||
# If any of the checks above exited with a non-zero exit code, the test will fail. | ||
reportResults |
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,2 @@ | ||
check "Check prepare-commit-msg is installed" test -f /usr/local/share/prepare-commit-msg-context/prepare-commit-msg | ||
check "Check prepare-commit-msg is executable" test -x /usr/local/share/prepare-commit-msg-context/prepare-commit-msg |