File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,6 +12,9 @@ cyan=$'\033[01;36m'
1212reset=$' \033 [0m'
1313yellow=$' \033 [33m'
1414
15+ # git は push 先リモート名を $1、URL を $2 で渡す
16+ remote_name=" $1 "
17+
1518while read -r _local_ref local_sha _remote_ref remote_sha
1619do
1720 # ブランチ削除の場合はスキップ
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
You can’t perform that action at this time.
0 commit comments