Skip to content

Commit ccc6fd5

Browse files
authored
Improve pre-commit message (#30476)
1 parent f92f723 commit ccc6fd5

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

.githooks/pre-commit.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ if (git rev-parse --verify HEAD 2>$null) {
1717
$against = "HEAD"
1818
}
1919
else {
20-
# Initial commit: diff against an empty tree object
21-
Write-Host "Using empty tree object as the previous commit"
20+
Write-Host "Using an empty tree object as the previous commit"
2221
$against = $(git hash-object -t tree /dev/null)
2322
}
2423

@@ -29,7 +28,10 @@ foreach ($file in $files) {
2928
# Check if the file contains secrets
3029
$detected = $(azdev scan -f $file | ConvertFrom-Json).secrets_detected
3130
if ($detected -eq "True") {
32-
Write-Host "Detected secrets from $file. You can run 'azdev mask' to remove secrets before commit." -ForegroundColor Red
31+
Write-Host "Detected secrets from $file. Please run the following command to mask it:" -ForegroundColor Red
32+
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" -ForegroundColor Red
33+
Write-Host "azdev mask -f $file" -ForegroundColor Red
34+
Write-Host "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" -ForegroundColor Red
3335
$hasSecrets = 1
3436
}
3537
}

.githooks/pre-commit.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@ then
1616
printf "Using HEAD as the previous commit\n"
1717
against=HEAD
1818
else
19-
printf "Using empty tree object as the previous commit\n"
19+
printf "Using an empty tree object as the previous commit\n"
2020
against=$(git hash-object -t tree /dev/null)
2121
fi
2222
has_secrets=0
23-
24-
IFS_OLD=${IFS}
25-
IFS=$'\n'
2623
for FILE in `git diff --cached --name-only --diff-filter=AM $against` ; do
2724
# Check if the file contains secrets
2825
detected=$(azdev scan -f "$FILE" | python -c "import sys, json; print(json.load(sys.stdin)['secrets_detected'])")
2926
if [ "$detected" = "True" ]; then
30-
printf "\033[0;31mDetected secrets from %s, You can run 'azdev mask' to remove secrets before commit.\033[0m\n" "$FILE"
27+
printf "\033[0;31mDetected secrets from %s, Please run the following command to mask it:\033[0m\n" "$FILE"
28+
printf "\033[0;31m+++++++++++++++++++++++++++++++++++++++++++++++++++++++\033[0m\n"
29+
printf "\033[0;31mazdev mask -f %s\033[0m\n" "$FILE"
30+
printf "\033[0;31m+++++++++++++++++++++++++++++++++++++++++++++++++++++++\033[0m\n"
3131
has_secrets=1
3232
fi
3333
done
34-
IFS=${IFS_OLD}
3534

3635
if [ $has_secrets -eq 1 ]; then
3736
printf "\033[0;31mSecret detected. If you want to skip that, run add '--no-verify' in the end of 'git commit' command.\033[0m\n"

0 commit comments

Comments
 (0)