diff_cover
diff_cover copied to clipboard
Command "git diff {branch}...HEAD" fails (master fetch doesn't help)
Jenkins SCM module does the following (minimal representation, it actually does a few more things):
git checkout [email protected]:<path>.git <dir>
cd <dir>
git checkout -f <commit-hash>
If I invoke git diff {branch}...HEAD
(as is done by diff-cover), I get the same error as is produced when running diff-cover:
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Preceding the diff with the recommended fetch does not work either:
git fetch origin $(TARGET_BRANCH):refs/remotes/origin/$(TARGET_BRANCH)
In this case, TARGET_BRANCH is "master", which is the repo's default branch.
Output of "git branch":
% git branch
* (HEAD detached at 0fcb182)
master
The full Jenkins SCM operation looks like this:
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url [email protected]:<repo-path> # timeout=10
Fetching upstream changes from [email protected]:<repo-path>
> git --version # timeout=10
using GIT_SSH to set credentials
> git -c core.askpass=true fetch --tags --progress [email protected]:<repo-path> +refs/pull/*:refs/remotes/origin/pr/* +refs/heads/master:refs/remotes/origin/master
> git rev-parse 0fcb1822ad5bcf71b9e0c7cddb85dcd5a54d4967^{commit} # timeout=10
Checking out Revision 0fcb1822ad5bcf71b9e0c7cddb85dcd5a54d4967 (detached)
> git config core.sparsecheckout # timeout=10
> git checkout -f 0fcb1822ad5bcf71b9e0c7cddb85dcd5a54d4967
> git rev-list 7ea84cf781acc06bb72767860dc1132d5663a90d # timeout=10
Howdy stranger!
I'll see if I can take a look at this. But as I've been saying in other things that have come up my free time has dried up dramatically recently so it may be a bit. We can talk in a less public forum if your curious.
But yeah, I'll try and look this week. No promises though
Hey, So the issue title makes me think you read the troubleshooting but I wanted to be extra sure.
When you say 'fetch master did not help' did you specifically make sure to try
git fetch origin master:refs/remotes/origin/master
from the readme?
No, I tried the troubleshooting tip, but it didn't work.
An explicit checkout of the target branch (master
) then switching back works, so I'm trying to figure out what happens differently in that case w/r/t symbolic references.
I believe if you do a fresh clone of a repo and snag a hash as described above you can reproduce reliably (don't need jenkins).
Hi @twall , @Bachmann1234 ,
I think I hit a similar problem. In my case I'm not using Jenkins but rather Teamcity. Also Teamcity does something like "git checkout -f
fatal: ambiguous argument 'origin/develop..HEAD': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]'
I'm not sure how to workaround this... any solution or workaround so far ?
For what it's worth... This didn't work.
- name: Make ${{ github.base_ref }} branch exist
run: |
git fetch origin master:refs/remotes/origin/master
diff_cover.command_runner.CommandError: fatal: ambiguous argument 'master...HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
But this did.
- name: Make ${{ github.base_ref }} branch exist
run: |
git checkout -b ${{ github.base_ref }} --track origin/${{ github.base_ref }}
git checkout -
Though now I'm just passing in the origin/master
or the parent hash depending. (isn't choosing either this or that just silly in GHA...)
- name: Run tox environment
env:
BASE_REF: ${{ fromJSON(format('[{0}, {1}]', toJSON(github.event.before), toJSON(format('origin/{0}', github.base_ref))))[github.base_ref != ''] }}
run: |
tox --skip-pkg-install -- --compare-branch="${BASE_REF}"
[testenv:check-coverage]
changedir = {toxinidir}
commands =
coverage combine coverage_reports/
coverage xml -o {toxinidir}/coverage.xml
coverage report --fail-under=90 --ignore-errors
diff-cover --fail-under=100 {posargs:--compare-branch=master} coverage.xml
https://github.com/Parquery/pylddwrap/pull/20
I was able to get this to work in GitHub Actions by doing 2 separate checkouts in my workflow (1 for master / main first, then the branch / ref that triggered the workflow, my PR branch in my case):
- name: Check out the repo
uses: actions/checkout@v2
with:
ref: master
- name: Check out the repo
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: "3.7"
- name: Install diff_cover
run: |
python -m pip install --upgrade pip
pip install diff_cover
- run: diff-cover coverage.xml --compare-branch=origin/master --diff-range-notation '..'
I have added this in case anyone else is trying to get diff_cover working with GitHub Actions