From a0a1834112e220d9da56f3d389fa3f98f8ded9d8 Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Mon, 3 Jul 2023 09:06:07 +0100 Subject: [PATCH] Prevent pushing branches to kubernetes repos directly Signed-off-by: Marcus Noble --- home/.dotfiles/aliases | 10 ++++++++++ home/.gitconfig | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/home/.dotfiles/aliases b/home/.dotfiles/aliases index 2d5e70d..8181793 100644 --- a/home/.dotfiles/aliases +++ b/home/.dotfiles/aliases @@ -76,6 +76,16 @@ git() { elif [ "$1" = "co" ]; then # Sign all commits shift _git checkout -b $@ + elif [ "$1" = "push" ]; then # Sign all commits + shift + if [ $# -eq 0 ]; then + remote_url=$(_git remote get-url $(git current-remote)) + if [[ $remote_url == *"kubernetes/"* ]] || [[ $remote_url == *"kubernetes-sigs/"* ]]; then + echo "⚠️ Don't push directly to Kubernetes" + return 1 + fi + fi + _git push $@ else _git $@ fi diff --git a/home/.gitconfig b/home/.gitconfig index 127473c..d84b129 100644 --- a/home/.gitconfig +++ b/home/.gitconfig @@ -51,7 +51,7 @@ logg = "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" dif = "!git diff -w" pop = "!git stash pop" - + current-remote = "!func(){ REMOTE=$(git rev-parse --abbrev-ref @{u}) ; echo ${REMOTE%/*} ; }; func" [help] autocorrect = 1