merge-branch icon indicating copy to clipboard operation
merge-branch copied to clipboard

New option to disable fastforwards so that Github does not add empty commits

Open andrewfenn opened this issue 3 years ago • 7 comments
trafficstars

I was experiencing a situation where this github action was polluting my commit log with empty commits because it merges fast forwards with no file changes..

image

This pull request adds a new feature and option to disable this behavior. You can add the option disable_fastforwards: true and have this action skip merging if it finds that no files were changed between the branches.

image

This can happen when you do the following:

  1. Have merge-branch setup to merge master into staging
  2. Update a file in branch staging and push to github
  3. Merge the staging branch into master and push master branch to github

The merge-branch action will see the fast forward and run the merge action on the API making it be treated as a new commit which isn't doing anything. This feature will disable that from happening by calling the comparison API and checking if the branches are identical or not.

andrewfenn avatar Jan 26 '22 05:01 andrewfenn

This change is in the public domain. Feel free to put under whatever license you wish.

andrewfenn avatar Jan 26 '22 05:01 andrewfenn

@andrewfenn isn't the purpose of this to actually do fast forward? :) Fast forward is what git does when two branches has not diverged, and just basically moves the pointer forward, without a merge commit.

Shouldn't the configuration be named "allow_fastforward" instead?

peterlauri avatar Feb 24 '22 18:02 peterlauri

Yes maybe not the correct terminology for this feature. It is suppose to prevent auto merging when there are only empty commits such as a merge with no file changes.

andrewfenn avatar Feb 25 '22 07:02 andrewfenn

I suggest you update the PR to have more correct got terminology. It is called fastforward what you (we) want :)

peterlauri avatar Feb 25 '22 07:02 peterlauri

This doesn't enable fastforwards. I am a little confused over the terminology, but this disables any sort of merging if the branches' files are identical thus not resulting in a commit that is empty of file changes. The point of fastforwards is to move the pointer forward if there is no divergent work to merge together. Thus the reason I chose the name disable_fastforwards, because we're disabling merge-branch from acting upon them and creating an empty commit via the github API.

Hope that makes sense. Feel free to change the option if you'd like. I won't be updating the PR because I can see this repo is inactive with a lot of open PRs not looked into. I think it would be a waste of my time if it's just going to rot in the PR section. I mostly posted this for others to use in case they wanted the same feature.

andrewfenn avatar Feb 28 '22 06:02 andrewfenn

@andrewfenn ok. What I wanted was to have FF. I stopped using this action and just doing plain github commands instead.

name: Master -> Develop
on:
  push:
    branches:
      - master
jobs:
  sync-branch:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        name: Git checkout
        with:
          token: ${{ secrets.PETER_GH_PERSONAL_TOKEN }}
          fetch-depth: 0
      - name: Merge master -> develop
        run: |
          git config user.name "GitHub Actions"
          git config user.email "[email protected]"
          git checkout develop
          git merge -m 'master -> develop' master
          git push origin develop

peterlauri avatar Mar 02 '22 09:03 peterlauri

@peterlauri Thanks for writing this up I will test this out. Maybe this will work better for me.

andrewfenn avatar Sep 19 '22 08:09 andrewfenn

@andrewfenn thanks for the PR y think is a good option, at least have print the message the merge was skipped.

MiguelSavignano avatar Oct 20 '22 00:10 MiguelSavignano