devmasx / merge-branch

A GitHub Action that merge PR branch to other branchs
161 stars 58 forks source link

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

Closed andrewfenn closed 1 year ago

andrewfenn commented 2 years ago

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 commented 2 years ago

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

peterlauri commented 2 years ago

@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?

andrewfenn commented 2 years ago

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.

peterlauri commented 2 years ago

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

andrewfenn commented 2 years ago

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.

peterlauri commented 2 years ago

@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 "peterlauri@gmail.com"
          git checkout develop
          git merge -m 'master -> develop' master
          git push origin develop
andrewfenn commented 1 year ago

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

MiguelSavignano commented 1 year ago

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