Open kuahyeow opened 2 years ago
I did manage to reproduce this locally as well - will post these steps soon.
We worked around this with the following monkey-patch
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'undercover'
module Undercover
class Changeset
# Rugged merge_base complains when graft/shallow
# (https://github.com/libgit2/rugged/issues/846)
#
# So we assume we provide the merge-base ourself. Modified from
# https://github.com/grodowski/undercover/blob/32e62f66682ee566032b5970437ed2934ef29701/lib/undercover/changeset.rb#L74-L78
def compare_base_obj
return unless compare_base
repo.lookup(compare_base.to_s)
end
end
end
compare_base = ARGV[0]
compare_base ||= IO.popen(%w(git merge-base origin/master HEAD)) { |p| p.read.chomp }
result = Undercover::CLI.run(%W(-c #{compare_base}))
exit result
I'm happy to draft up some PR but unsure if this should be another configuration option, or something else.
Thanks for reporting this @kuahyeow, I remember getting compare_base_obj
to work wasn't so obvious and I am aware that merge_base
may stop working for shallow clones.
I'm happy to draft up some PR but unsure if this should be another configuration option, or something else.
I appreciate it and would be happy to help too. My initial thought is that ideally this wouldn't require any extra configuration, given that it's possible to infer what has been passed to --compare
? If it's a ref, just look it up like in your workaround and only otherwise scan for the merge_base
. I don't know it's doable with the current rugged
API and will be looking more into it
Thanks for reporting this @kuahyeow, I remember getting
compare_base_obj
to work wasn't so obvious and I am aware thatmerge_base
may stop working for shallow clones.I'm happy to draft up some PR but unsure if this should be another configuration option, or something else.
I appreciate it and would be happy to help too. My initial thought is that ideally this wouldn't require any extra configuration, given that it's possible to infer what has been passed to
--compare
? If it's a ref, just look it up like in your workaround and only otherwise scan for themerge_base
. I don't know it's doable with the currentrugged
API and will be looking more into it
@grodowski In GitLab's case, we pass in a SHA to --compare
and not a ref. So not sure that will work.
For example, GitLab CI provides a variable called CI_MERGE_REQUEST_TARGET_BRANCH_SHA
which is already the merge-base of the feature branch, and the main branch. It's value looks like 91a9efed376560f1f4ce35f350bfc52520cbbc7b
.
Possible ideas:
--compare
to never get merge-base itself, require user to do it themself (breaking change)--[no-]compare-merge-base
. If --no-compare-merge-base
, undercover skips getting the merge base from --compare
. If --compare-merge-base
, undercover gets the merge base from --compare
as per now.I made some recent changes to UndercoverCI to use shallow clones for a performance boost, which led me back here. I started a branch (https://github.com/grodowski/undercover/commit/31fbda6f5393d7f270bdbfdce17279cb027d2782) where compare_base_obj
can fall back to the specific compare
value if the merge base doesn't exist.
It looks like 1. proposed by @kuahyeow and so far I haven't considered adding new CLI options. Will probably ship this in a new major version after adding some test coverage.
On GitLab CI, the default depth for the cloned git repository is 50 (for projects like https://gitlab.com/gitlab-org/gitlab/, we set it even lower to 20, for speed purposes).
This leads to errors like below
From https://gitlab.com/gitlab-org/gitlab/-/jobs/2627986054
Steps to reproduce
undercover -c ${CI_MERGE_REQUEST_TARGET_BRANCH_SHA}
https://github.com/libgit2/rugged/issues/846#issuecomment-983047575 seems related.