NPM Package repos: diff view fails for different versions
Created by: varungandhi-src
Slack discussion: https://sourcegraph.slack.com/archives/CMMTWQQ49/p1646059562163539
The diff view currently doesn't work because it is unable to find a merge base. Example: https://sourcegraph.com/npm/types/lodash/-/compare/v4.14.104...v4.14.102 . This is because different versions are encoded as unrelated commits, which do not share any common ancestors.
Technically, it should be possible to diff two commits even if they don't have any common ancestors. However, at the moment, we diff from the merge-base because:
-
Doing that works well for batch changes too. https://github.com/sourcegraph/sourcegraph/pull/11117#discussion_r433678921
-
Sometimes diffing directly can give counter-intuitive results. Example from Erik in Slack:
➜ tmp git:(master) cat index.html ASDF 123 Another change ➜ tmp git:(master) git diff master...test-branch | cat diff --git a/index.html b/index.html index 53099b8..8142fb7 100644 --- a/index.html +++ b/index.html @@ -1,3 +1,5 @@ ASDF 123 + +Change C
I think it’s this weird thing, the file on master contains “Another change” but in the git diff that doesn’t appear (because the branch is based on master^)
One option to fix this is to fall back to diffing directly if there is no merge base.