Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error fatal: refusing to merge unrelated histories appears #10

Open
JorgeAguilarOrozco opened this issue Feb 10, 2022 · 3 comments
Open

Comments

@JorgeAguilarOrozco
Copy link

JorgeAguilarOrozco commented Feb 10, 2022

I was trying to merge automatically from master branch to the develop branch. The result is the following:

  'Nightly Merge Action' is using the following input:
      - stable_branch = 'master'
      - development_branch = 'develop'
      - allow_ff = true
      - allow_git_lfs = 
      - ff_only = false
      - allow_forks = true
      - user_name = GitHub Nightly Merge Action
      - user_email = actions@github.com
      - push_token = GITHUB_TOKEN = ***
  
  + git fetch origin master
  From https://github.com/JorgeAguilarOrozco/nodejs-typescript-template
   * branch            master     -> FETCH_HEAD
  + git checkout master
  Already on 'master'
  + git pull
  Your branch is up to date with 'origin/master'.
  From https://github.com/JorgeAguilarOrozco/nodejs-typescript-template
   * [new branch]      develop    -> origin/develop
  Already up to date.
  + git fetch origin develop
  From https://github.com/JorgeAguilarOrozco/nodejs-typescript-template
   * branch            develop    -> FETCH_HEAD
  + git checkout develop
  Switched to a new branch 'develop'
  Branch 'develop' set up to track remote branch 'develop' from 'origin'.
  + git pull
  Already up to date.
  + git merge-base --is-ancestor master develop
  + set +o xtrace
  
    'Nightly Merge Action' is trying to merge the 'master' branch (958eaac3d69f2351ae9e9051[19](https://github.com/JorgeAguilarOrozco/nodejs-typescript-template/runs/5133418812?check_suite_focus=true#step:4:19)bd0ecd40c64158)
    into the 'develop' branch (58ceba7b9d2763fe[21](https://github.com/JorgeAguilarOrozco/nodejs-typescript-template/runs/5133418812?check_suite_focus=true#step:4:21)fa[32](https://github.com/JorgeAguilarOrozco/nodejs-typescript-template/runs/5133418812?check_suite_focus=true#step:4:32)d49[35](https://github.com/JorgeAguilarOrozco/nodejs-typescript-template/runs/5133418812?check_suite_focus=true#step:4:35)19671e19ffe[42](https://github.com/JorgeAguilarOrozco/nodejs-typescript-template/runs/5133418812?check_suite_focus=true#step:4:42))
  
  + git merge --ff --no-edit master
  fatal: refusing to merge unrelated histories

This is my YAML file:

# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches: [ master ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2

      - name: Nightly Merge
        # You may pin to the exact commit or the version.
        # uses: robotology/gh-action-nightly-merge@4047e51ca91b0629e5c66eb69e0f59ffba33d97b
        uses: robotology/gh-action-nightly-merge@v1.3.2
        with:
          # Name of the stable branch
          stable_branch: master
          # Name of the development branch
          development_branch: develop
          # Allow fast forward merge
          allow_ff: true
          # Allow action to run on forks
          allow_forks: true
        env:
            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@killianhuyghe
Copy link

killianhuyghe commented May 10, 2022

This is because:

  • checkout only fetches the last commit by default
  • Nightly Merge uses git merge-base --is-ancestor, which checks for a common ancestor

So you don't have enough past commits to find a common ancestor.
You can fix this by changing how many past commits are fetched by checkout.

With your current configuration and assuming both of your branches are in sync when you update your GitHub action, fetching 2 commits should be enough (as the previous commit should be the common ancestor). But you may use more than two to have some margin for errors.

      - uses: actions/checkout@v2
        with:
          fetch-depth: 2

@Cyberboss
Copy link

I think the easiest workaround for this is to use uses: actions/checkout@v1. v1 appears to use full clones which prevent this issue.

@traversaro
Copy link
Member

Thanks for the helpful answers @Cyberboss and @killianhuyghe ! If I am not wrong @JorgeAguilarOrozco there is nothing we can do on this repo side, except perhaps improve the documentation (any PR on that aspect would be welcome). So do you agree if I close the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants