From 4053d9d3488f6f060207bbbd4add6fc25dc6f619 Mon Sep 17 00:00:00 2001 From: Timur Karimov Date: Fri, 1 Mar 2024 10:26:11 +0100 Subject: [PATCH] Avoid accidental pushes to `develop` and `trunk` (#8287) Co-authored-by: Timur Karimov --- .husky/pre-push | 16 ++++++++++++++++ changelog/avoid-accidental-push-to-develop | 4 ++++ 2 files changed, 20 insertions(+) create mode 100755 .husky/pre-push create mode 100644 changelog/avoid-accidental-push-to-develop diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100755 index 00000000000..3dc4fa4bcd0 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,16 @@ +#!/bin/bash +. "$(dirname "$0")/_/husky.sh" + +# Allows us to read user input below, redirects script's input to the terminal. +exec < /dev/tty + +PROTECTED_BRANCH=("develop" "trunk") +CURRENT_BRANCH=$(git branch --show-current) + +if [[ " ${PROTECTED_BRANCH[@]} " =~ " ${CURRENT_BRANCH} " ]]; then + read -p "$CURRENT_BRANCH is a protected branch. Are you sure you want to push? (y/n): " confirmation + if [ "$confirmation" != "y" ]; then + echo "Push aborted" + exit 1 + fi +fi \ No newline at end of file diff --git a/changelog/avoid-accidental-push-to-develop b/changelog/avoid-accidental-push-to-develop new file mode 100644 index 00000000000..b1a0fee6648 --- /dev/null +++ b/changelog/avoid-accidental-push-to-develop @@ -0,0 +1,4 @@ +Significance: minor +Type: dev + +Dev: additional check when pushing to protected branches.