Skip to content

Commit 8c34108

Browse files
authored
{CI} Fix file name space when iterating git diffs for secret scan task (#30434)
* fix file name space when iterating git diffs * fix * revert double quote
1 parent a0059e4 commit 8c34108

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

.githooks/pre-commit.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ else
2020
against=$(git hash-object -t tree /dev/null)
2121
fi
2222
has_secrets=0
23+
24+
IFS_OLD=${IFS}
25+
IFS=$'\n'
2326
for FILE in `git diff --cached --name-only --diff-filter=AM $against` ; do
2427
# Check if the file contains secrets
2528
detected=$(azdev scan -f "$FILE" | python -c "import sys, json; print(json.load(sys.stdin)['secrets_detected'])")
@@ -28,6 +31,7 @@ for FILE in `git diff --cached --name-only --diff-filter=AM $against` ; do
2831
has_secrets=1
2932
fi
3033
done
34+
IFS=${IFS_OLD}
3135

3236
if [ $has_secrets -eq 1 ]; then
3337
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"

azure-pipelines.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,13 +1137,17 @@ jobs:
11371137
. env/bin/activate
11381138
git fetch origin --depth=1 $(System.PullRequest.TargetBranch)
11391139
declare -A secret_files
1140+
IFS_OLD=${IFS}
1141+
IFS=$'\n'
11401142
for FILE in `git diff --name-only --diff-filter=AM origin/$(System.PullRequest.TargetBranch)` ; do
1143+
echo $FILE
11411144
detected=$(azdev scan -f "$FILE" | python -c "import sys, json; print(json.load(sys.stdin)['secrets_detected'])")
11421145
if [ $detected == 'True' ]; then
11431146
printf "\033[0;31mDetected secrets from %s, You can run 'azdev mask' to remove secrets.\033[0m\n" "$FILE"
11441147
secret_files+=$FILE
11451148
fi
11461149
done
1150+
IFS=${IFS_OLD}
11471151
if [ "${#secret_files[@]}" -gt 0 ]; then
11481152
exit 1
11491153
fi

0 commit comments

Comments
 (0)