question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Command "git diff {branch}...HEAD" fails (master fetch doesn't help)

See original GitHub issue

Jenkins SCM module does the following (minimal representation, it actually does a few more things):

git checkout git@github.com:<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 git@github.com:<repo-path> # timeout=10
Fetching upstream changes from git@github.com:<repo-path>
 > git --version # timeout=10
using GIT_SSH to set credentials 
 > git -c core.askpass=true fetch --tags --progress git@github.com:<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

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
f18mcommented, Dec 26, 2020

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 <commit-hash>” at some point and thus clones the git repo in a “HEAD detached” condition (https://www.git-tower.com/learn/git/faq/detached-head-when-checkout-commit/). I tried and indeed a command like “git diff origin/develop…HEAD” in such condition fails with error

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 ?

0reactions
dmcconnell-mcommented, Nov 23, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

[rejected] master -> master (fetch first) - git - Stack Overflow
The answer is there, git is telling you to fetch first. Probably somebody else has pushed to master already, and your commit is...
Read more >
git-fetch Documentation - Git
By default git fetch refuses to update the head which corresponds to the current branch. This flag disables the check.
Read more >
git: fetch and merge, don't pull | Mark's Blog
The other problem is that by both fetching and merging in one command, your working directory is updated without giving you a chance...
Read more >
Merging vs. Rebasing | Atlassian Git Tutorial
Compare git rebase with the related git merge command and identify all of the potential opportunities to ... Merging master into the feature...
Read more >
Fix git “tip of your current branch is behind its remote ...
git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found