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

Danger fails with "Cannot find a merge base between danger_base and danger_head" #768

Open
php-coder opened this issue Mar 30, 2017 · 22 comments

Comments

@php-coder
Copy link

Report

What did you do?

I'm running danger on Travis CI from a pull request.

What did you expect to happen?

Danger shouldn't crash.

What happened instead?

There is no comment on a PR and in the travis log I see the following error:

remote: Counting objects: 5, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 0), reused 5 (delta 0), pack-reused 0
Unpacking objects: 100% (5/5), done.
From https://github.com/php-coder/mystamps
 * [new tag]         0.1        -> 0.1
 * [new tag]         0.1.1      -> 0.1.1
 * [new tag]         0.1.2      -> 0.1.2
 * [new tag]         0.1.3      -> 0.1.3
 * [new tag]         0.2        -> 0.2
 * [new tag]         0.3        -> 0.3
/home/travis/.rvm/gems/ruby-2.2.5/gems/danger-4.3.2/lib/danger/scm_source/git_repo.rb:77:in `find_merge_base': Cannot find a merge base between danger_base and danger_head. (RuntimeError)
	from /home/travis/.rvm/gems/ruby-2.2.5/gems/danger-4.3.2/lib/danger/scm_source/git_repo.rb:16:in `diff_for_folder'
	from /home/travis/.rvm/gems/ruby-2.2.5/gems/danger-4.3.2/lib/danger/danger_core/dangerfile.rb:259:in `setup_for_running'
	from /home/travis/.rvm/gems/ruby-2.2.5/gems/danger-4.3.2/lib/danger/danger_core/dangerfile.rb:269:in `run'
	from /home/travis/.rvm/gems/ruby-2.2.5/gems/danger-4.3.2/lib/danger/danger_core/executor.rb:27:in `run'
	from /home/travis/.rvm/gems/ruby-2.2.5/gems/danger-4.3.2/lib/danger/commands/runner.rb:66:in `run'
	from /home/travis/.rvm/gems/ruby-2.2.5/gems/claide-1.0.1/lib/claide/command.rb:334:in `run'
	from /home/travis/.rvm/gems/ruby-2.2.5/gems/danger-4.3.2/bin/danger:5:in `<top (required)>'
	from /home/travis/.rvm/gems/ruby-2.2.5/bin/danger:22:in `load'
	from /home/travis/.rvm/gems/ruby-2.2.5/bin/danger:22:in `<main>'
	from /home/travis/.rvm/gems/ruby-2.2.5/bin/ruby_executable_hooks:15:in `eval'
	from /home/travis/.rvm/gems/ruby-2.2.5/bin/ruby_executable_hooks:15:in `<main>'

Your Environment

  • Which CI are you running on? Travis CI
  • Are you running the latest version of Danger? yes
  • What is your Dangerfile? It's here but error doesn't relate to my configuration
@php-coder
Copy link
Author

This issue is reproduced on one of my PRs and danger doesn't work at all :(

@orta
Copy link
Member

orta commented Apr 4, 2017

Does 4.3.1?

@php-coder
Copy link
Author

4.3.2 Should I try 4.3.1?

@orta
Copy link
Member

orta commented Apr 4, 2017

There were changes around this in 4.3.2 - CHANGELOG

Might be worth seeing if they affected you.

@php-coder
Copy link
Author

No, it's definitely not related to a new version because another PR is also running on a new version and doesn't fail with such error.

@orta
Copy link
Member

orta commented Apr 4, 2017

Sounds like this is a dupe of #768 then

@php-coder
Copy link
Author

Sounds like this is a dupe of #768 then

Duplicate of itself? :)

@orta
Copy link
Member

orta commented Apr 4, 2017

ah yeah, #660

php-coder added a commit to php-coder/mystamps that referenced this issue Apr 5, 2017
@php-coder
Copy link
Author

No, it's definitely not related to a new version because another PR is also running on a new version and doesn't fail with such error.

I was wrong, it fails on both of PRs. I'm trying to rollback to 4.3.1

@php-coder
Copy link
Author

php-coder commented Apr 6, 2017

I confirm that rolling back to 4.3.1 is solving this error.

@orta
Copy link
Member

orta commented Apr 7, 2017

I wonder if different versions of git have different behaviour here, can you leave some breadcrumbs in #660 so that you or others can debug 👍

@php-coder
Copy link
Author

I'm not sure that this issue is the same as #660 because error messages and stack traces are different.

@orta
Copy link
Member

orta commented Apr 8, 2017

Changes due to #660 were the only thing that shipped in 4.3.1

@php-coder
Copy link
Author

Could it be related to custom git clone depth in TravisCI?

git:
  depth: 1

@orta
Copy link
Member

orta commented Apr 15, 2017

Yep, that would make sure that the commits Danger is looking for would need to be re-downloaded

@kgaidis
Copy link

kgaidis commented Jul 31, 2017

We had this error because there were two branches with the same name: feature/iOS-11 and feature/ios-11 (a mistake). Deleting one of the branches fixed the error.

The tricky thing is that PR's unrelated to these branches were failing, so out of nowhere, all PR's were failing.

Could there be some branch naming collision "bug" in Danger?

Related: https://stackoverflow.com/a/38494084/826435

bundler: failed to load command: danger (/Users/behance/.rbenv/versions/2.3.1/bin/danger)
RuntimeError: Cannot find a merge base between danger_base and danger_head.
  /Users/behance/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/danger-5.3.2/lib/danger/scm_source/git_repo.rb:104:in `find_merge_base'
  /Users/behance/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/danger-5.3.2/lib/danger/scm_source/git_repo.rb:16:in `diff_for_folder'
  /Users/behance/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/danger-5.3.2/lib/danger/danger_core/dangerfile.rb:259:in `setup_for_running'
  /Users/behance/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/danger-5.3.2/lib/danger/danger_core/dangerfile.rb:269:in `run'
  /Users/behance/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/danger-5.3.2/lib/danger/danger_core/executor.rb:27:in `run'
  /Users/behance/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/danger-5.3.2/lib/danger/commands/runner.rb:66:in `run'
  /Users/behance/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/claide-1.0.2/lib/claide/command.rb:334:in `run'
  /Users/behance/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/danger-5.3.2/bin/danger:5:in `<top (required)>'
  /Users/behance/.rbenv/versions/2.3.1/bin/danger:22:in `load'
  /Users/behance/.rbenv/versions/2.3.1/bin/danger:22:in `<top (required)>'
Build step 'Execute shell' marked build as failure
[BFA] Scanning build for known causes...
[BFA] No failure causes found
[BFA] Done. 0s

bodom91 pushed a commit to bodom91/mystamps that referenced this issue Aug 2, 2017
@zdnk
Copy link

zdnk commented Sep 4, 2017

I have this issue too with jenkins and Bitbucket.
This is our config:
screen shot 2017-09-04 at 20 03 08
And what it does:
screen shot 2017-09-04 at 20 06 02

@raymondhoagland
Copy link

raymondhoagland commented Oct 20, 2017

I'm seeing this as well with Jenkins and Github. We are doing shallow clones with a depth of 1 and the error appears to be sporadic.

Most of the time the job works fine, but ~20% it runs into the error. Usually running the job again seems to fix it which makes it even more confusing for us to track down.


Seems almost like it bails every time fetch has to do either a forced update or gets a new ref.

@iwasrobbed-ks
Copy link

Just dropping a breadcrumb: we were doing shallow clones on CI for PR builds and once the # of commits on that PR surpassed that depth, it started failing with this error

@JoeSSS
Copy link
Member

JoeSSS commented Jan 10, 2019

It feels like danger does some black magic to get the base and the HEAD, which is not really compatible to what shallow clone is about. What helped to me is adding master additionally to refspec: +refs/pull/${ghprbPullId}/merge:refs/remotes/origin/pr/${ghprbPullId}/merge +refs/heads/master:refs/remotes/origin/master and then defining base and the head on my own while calling danger like: danger --head=\$(git rev-parse HEAD) --base=\$(git rev-parse origin/master) ....

@kgaidis
Copy link

kgaidis commented Jan 10, 2019

I think I forgot to comment on an update.

I'm pretty sure that what @rob-keepsafe said worked. We had shallow clone of depth 1, and once it was changed to shallow clone of depth 100 it has worked since. The 100 is just a random number to maximize the chance of this issue not happening.

@JCarlosR
Copy link

JCarlosR commented Aug 23, 2023

I tried with depth 100 and bigger numbers, also disabling shadow clone, but still get this error:

bundler: failed to load command: danger (/root/.asdf/installs/ruby/3.2.1/bin/danger)
/root/.asdf/installs/ruby/3.2.1/lib/ruby/gems/3.2.0/gems/danger-9.3.1/lib/danger/scm_source/git_repo.rb:135:in `find_merge_base': Cannot find a merge base between danger_base and danger_head. If you are using shallow clone/fetch, try increasing the --depth (RuntimeError)

Any insights on what else could be causing this?

On the logs I see the repo being completely cloned (all branches, tags).

Edit: Might be related to this.

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

8 participants