Nir Azkiel
Nir Azkiel

Reputation: 61

Force Azure DevOps to allow only Fast Forward Merge

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

Answers (2)

Leo Liu
Leo Liu

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”).

enter image description here

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

CodeWizard
CodeWizard

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


Enforce a merge strategy

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.

enter image description here Set merge requirements

  • No fast-forward merge - This option merges the commit history of the source branch when the pull request closes and creates a merge commit in the target branch.
  • Squash merge - Complete all pull requests with a squash merge, creating a single commit in the target branch with the changes from the source branch. Learn more about squash merging and how it affects your branch history.

Using git hook to enforce this option

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

Related Questions