From 8ce2d49a0463b3483b4e88b7c8fc902f67a2bec6 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 30 May 2024 17:08:53 -0400 Subject: [PATCH 1/3] shebang fix for win, prevent error on ci merges --- prevent_commit_to_main.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prevent_commit_to_main.sh b/prevent_commit_to_main.sh index 5237b16a..d66d4158 100755 --- a/prevent_commit_to_main.sh +++ b/prevent_commit_to_main.sh @@ -1,9 +1,9 @@ -#!/bin/sh +#!/usr/bin/env sh ##!"C:\\Program Files\\Git\\usr\\bin\\bash.exe" branch="$(git rev-parse --abbrev-ref HEAD)" -if [ "$branch" = "main" ]; then +if [ "$branch" = "main" ] && [ -z "$MERGE_HEAD" ]; then echo "You are on the main branch. Committing to the main branch is not allowed." exit 1 fi From d73843f7399c038a207c95e5035408da1ab6e5da Mon Sep 17 00:00:00 2001 From: = Date: Thu, 30 May 2024 17:14:22 -0400 Subject: [PATCH 2/3] git fix --- prevent_commit_to_main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prevent_commit_to_main.sh b/prevent_commit_to_main.sh index d66d4158..d9742ec6 100755 --- a/prevent_commit_to_main.sh +++ b/prevent_commit_to_main.sh @@ -3,7 +3,7 @@ branch="$(git rev-parse --abbrev-ref HEAD)" -if [ "$branch" = "main" ] && [ -z "$MERGE_HEAD" ]; then +if [ "$branch" = "main" ] && [ -z "${GIT_DIR}/MERGE_MODE" ]; then echo "You are on the main branch. Committing to the main branch is not allowed." exit 1 fi From 9c45a51c41d6acec5aea9534b9153274f2bb94c1 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 30 May 2024 17:18:29 -0400 Subject: [PATCH 3/3] Make explicit merge to master --- prevent_commit_to_main.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/prevent_commit_to_main.sh b/prevent_commit_to_main.sh index d9742ec6..01f8d241 100755 --- a/prevent_commit_to_main.sh +++ b/prevent_commit_to_main.sh @@ -3,7 +3,12 @@ branch="$(git rev-parse --abbrev-ref HEAD)" -if [ "$branch" = "main" ] && [ -z "${GIT_DIR}/MERGE_MODE" ]; then -echo "You are on the main branch. Committing to the main branch is not allowed." -exit 1 +if [ "$branch" = "main" ]; then + if [ -z "${GIT_DIR}/MERGE_MODE" ]; then + echo "Merge to main allowed." + exit 0 + else + echo "You are on the main branch. Committing to the main branch is not allowed." + exit 1 + fi fi