Reputation: 1
We are trying to leverage the GitLab app for Jira. When beginning work on a new issue, there is a development setion that allows you to create a GitLab branch. We would like to set an UPDATE BRANCH NAME FORMAT default for all developers. Curious if this can be done (cannot figure out yet) or does each developer need to set individually (this works).
Upvotes: 0
Views: 19
Reputation: 21
You can implement server-side Git hooks on your GitLab server (or GitLab.com if you have sufficient permissions). A pre-receive hook can inspect the branch name before the branch is pushed to the remote repository. If the name doesn't match your defined pattern, the push is rejected.
Strong enforcement; prevents non-compliant branches from entering the main repository.
Requires server-side configuration (more complex); can be disruptive if not carefully implemented (developers might get blocked); doesn't provide feedback within Jira. This is the only option that truly enforces the standard.
#!/bin/bash
# (Simplified example - needs error handling, logging, etc.)
while read oldrev newrev refname; do
branch_name=$(basename "$refname")
# Regex to match the desired pattern (adjust as needed)
if [[ ! $branch_name =~ ^(feature|bugfix|hotfix)/[A-Z]+-[0-9]+-.*$ ]]; then
echo "Error: Branch name '$branch_name' does not match the required format."
echo " Expected format: feature/PROJECT-123-description"
exit 1
fi
done
exit 0
Upvotes: 2