EN VI

Git - fatal: ambiguous argument 'origin/master...HEAD': unknown revision or path not in the working tree in Azure DevOps?

2024-03-14 22:00:10
How to Git - fatal: ambiguous argument 'origin/master...HEAD': unknown revision or path not in the working tree in Azure DevOps

I want to check the formatting of modified Python files in Azure DevOps. I'm only using git branch -a to see what's going on. I don't have permissions to use git fetch.

Currently running this:

jobs:
  - job: Linting
    displayName: Format code
    steps:
      - task: UsePythonVersion@0
        inputs:
          versionSpec: 3.x

      - script: |
          pip install black
        displayName: 'Install Black'

      - script: |
          git branch -a
          git diff --name-only origin/master...HEAD --diff-filter=AM | grep '\.py$' | xargs black --check 
        displayName: 'Format files'

Which gives me this error:

* (HEAD detached at origin/11111111111xxxxxx)
  remotes/origin/11111111111xxxxxx
fatal: ambiguous argument 'origin/master...HEAD': unknown revision or path not in the working tree.

I branched directly off of master for my changes. I don't have any issues running this locally.

How can I fix this?

Solution:

To run git diff, disable shallow fetch on checkout:


  jobs: 
  - job: A
      steps:
      - checkout: self
        fetchDepth: 0
Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login