Reputation: 61
I would like to use Azure DevOps Pull Request with a strict behavior.
Merges are only done on the Development branch and the server Enforce only Fast Forward merges to master.
I did not found a way to force this behavior on Azure DevOps.
Is there a way to set this option?
Upvotes: 4
Views: 8786
Reputation: 76928
Force Azure DevOps to allow only Fast Forward Merge
Just like Erik P comment, this feature has been released with Sprint 150:
New merge types for completing pull requests:
You now have more options when merging the changes from a pull request to the target branch. We have added support for two of our most requested features on the Developer Community: Fast-Forward merging and Semi-Linear merging (also called “Rebase and Merge”).
But some folks saying this feature is not complete, if you have the same question, you could vote and add your comments for this feedback. When there are enough communities vote and add comments for this feedback, the product team member will take this feedback seriously.
Fast forward merge in pull requests
Hope this helps.
Upvotes: -1
Reputation: 142612
Taken from the docs: Looks like you can do it in a simple way, since FF is not supported as a selected merge stategy.
https://learn.microsoft.com/en-us/azure/devops/repos/git/branch-policies?view=azure-devops
Maintain a consistent branch history by enforcing a merge strategy when a pull request finishes. Select Enforce a merge strategy and pick an option to require that pull requests merge using that strategy.
You can do it by setting up git hook which will verify that the commit you are pushing is "on top" of the required commit
#!/bin/sh
# for details see here,
# http://git-scm.com/book/en/Customizing-Git-An-Example-Git-Enforced-Policy
refname=$1
oldrev=$2
newrev=$3
# enforces fast-forward only pushes
check_fast_forward ()
{
all_refs=`git rev-list ${oldrev}..${newrev} | wc -l`
single_parent_refs=`git rev-list ${oldrev}..${newrev} --max-parents=1 | wc -l `
if [ $all_refs -eq $single_parent_refs ]; then
echo "This is the section for fast-forward commits ..."
exit 0
fi
}
check_fast_forward
Upvotes: 1