Skip to content

Commit c428d6d

Browse files
committed
support other remotes
1 parent c6760de commit c428d6d

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

git/hooks/pre-push-gitleaks.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ cyan=$'\033[01;36m'
1212
reset=$'\033[0m'
1313
yellow=$'\033[33m'
1414

15+
# git は push 先リモート名を $1、URL を $2 で渡す
16+
remote_name="$1"
17+
1518
while read -r _local_ref local_sha _remote_ref remote_sha
1619
do
1720
# ブランチ削除の場合はスキップ
@@ -26,15 +29,21 @@ do
2629
# 理想: remote_shaがローカルに存在する
2730
range="$remote_sha..$local_sha"
2831
else
29-
# フォールバック: originに未到達の全コミットをスキャン
32+
# フォールバック: push先リモートに未到達の全コミットをスキャン
3033
# 新規ブランチ、remote_sha欠落、force push等で使用
3134
if [ "$remote_sha" = "$z40" ]
3235
then
33-
printf -- '%sInfo: new branch, scanning commits not yet in origin%s\n' "$cyan" "$reset" >&2
36+
printf -- '%sInfo: new branch, scanning commits not yet in %s%s\n' "$cyan" "$remote_name" "$reset" >&2
37+
else
38+
printf -- '%sWarning: remote SHA not found locally, scanning commits not yet in %s%s\n' "$yellow" "$remote_name" "$reset" >&2
39+
fi
40+
# push先が名前付きリモートならそのリモートを、URL直push等なら全リモートを除外対象にする
41+
if git remote | grep -Fqx -- "$remote_name"
42+
then
43+
range="$local_sha --not --remotes=$remote_name"
3444
else
35-
printf -- '%sWarning: remote SHA not found locally, scanning commits not yet in origin%s\n' "$yellow" "$reset" >&2
45+
range="$local_sha --not --remotes"
3646
fi
37-
range="$local_sha --not --remotes=origin"
3847
fi
3948

4049
gitleaks git --log-opts="$range" --no-banner --verbose || exit 1

0 commit comments

Comments
 (0)