Skip to content

Commit

Permalink
git - Allow commit to unborn main branch
Browse files Browse the repository at this point in the history
Allow committing directly to the main branch if it doesn't contain any
commits. This will make it easier to get initial work ready to push to
remote repo prior to requiring updates via PR.
  • Loading branch information
aschrab committed Feb 22, 2021
1 parent 286c2a6 commit 16431fc
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions git_template/hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ fi

if [ "$(git config --type=bool --default=no commit.allowedOnMain)" = false ]
then
case "$(git symbolic-ref HEAD)" in
refs/heads/master|refs/heads/main)
echo "Create a new branch before committing, or set commit.allowedOnMain" >&2
exit 1
;;
esac
ref=$(git symbolic-ref HEAD)

# Allow initial commit to main branch
if git rev-parse "$ref" >/dev/null 2>&1
then
case "$ref" in
refs/heads/master|refs/heads/main)
echo "Create a new branch before committing, or set commit.allowedOnMain" >&2
exit 1
;;
esac
fi
fi

0 comments on commit 16431fc

Please sign in to comment.