For CI jobs that need to work on the diff on an MR, I would like to fetch the source branch and target branch with enough history to reliably run something like git diff main...mr
(where main
is the target branch and mr
is the source branch). (I.e., the history should include mr
and go back far enough to find the merge-base.)
An unreliable and inefficient way to do this is to pick a depth that's likely to be enough (say 1024), and git fetch --depth=1024 mr && git fetch --depth=1024 main
, but for extreme edge cases 1024 may not be enough, and in the normal case it fetches way more history than necessary.
We are using GitLab CI, so if there's no generic way to fetch up to a merge-base in git
, any GitLab-specific solutions are welcome too.
As specific example, clang-tidy-diff
is one of the tools I want to use that requires the diff.