GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: crash on ambiguous ref 'HEAD' by tusharsadhwani · Pull Request #3425 · pre-commit/pre-commit

Conversation

@tusharsadhwani

@tusharsadhwani tusharsadhwani commented Mar 13, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

I lost the log when I faced this crash, but it was of the form:

CalledProcessError: ('git', 'diff', '--name-only', '--no-ext-diff', '-z', '-m', '1234abc', 'HEAD', 'MERGE_HEAD'): Ambiguous reference 'HEAD'
... something about prepending '--', like
git diff ref [ref2] -- [files]

Likely happened because there is a folder named head in the base commit SHA.

And this fixes the issue. If you have more information on how I can create a minimal reproduction of the bug and add it as a test, I'd be happy to.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@asottile
asottile force-pushed the ambiguous-ref branch from d51bdbf to b7eb412 Compare March 15, 2025 19:22
@tusharsadhwani @asottile
fix: crash on ambiguous ref 'HEAD'
b7eb412
asottile
asottile approved these changes Mar 15, 2025
View reviewed changes

@asottile asottile left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a test which failed with:

=================================== FAILURES ===================================
________________ test_get_conflicted_files_with_file_named_head ________________
/home/asottile/workspace/pre-commit/tests/git_test.py:149: in test_get_conflicted_files_with_file_named_head
    ret = set(git.get_conflicted_files())
/home/asottile/workspace/pre-commit/pre_commit/git.py:127: in get_conflicted_files
    cmd_output(
/home/asottile/workspace/pre-commit/pre_commit/util.py:117: in cmd_output
    returncode, stdout_b, stderr_b = cmd_output_b(*cmd, **kwargs)
/home/asottile/workspace/pre-commit/pre_commit/util.py:111: in cmd_output_b
    raise CalledProcessError(returncode, cmd, stdout_b, stderr_b)
E   pre_commit.util.CalledProcessError: command: ('/usr/bin/git', 'diff', '--name-only', '--no-ext-diff', '-z', '-m', 'ab3e3cf46f673553f5d9ca374de5fe0d2a1989c8', 'HEAD', 'MERGE_HEAD')
E   return code: 128
E   stdout: (none)
E   stderr:
E       fatal: ambiguous argument 'HEAD': both revision and filename
E       Use '--' to separate paths from revisions, like this:
E       'git <command> [<revision>...] -- [<file>...]'
----------------------------- Captured stdout call -----------------------------
[INFO] Checking merge-conflict files only.
------------------------------ Captured log call -------------------------------
INFO     pre_commit.git:git.py:115 Checking merge-conflict files only.
=========================== short test summary info ============================
FAILED tests/git_test.py::test_get_conflicted_files_with_file_named_head - pre_commit.util.CalledProcessError: command: ('/usr/bin/git', 'diff', '--na...
================= 1 failed, 10 passed, 22 deselected in 0.56s ==================

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@asottile
asottile enabled auto-merge March 15, 2025 19:24
@asottile
asottile merged commit ff7256c into pre-commit:main Mar 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@asottile asottile asottile approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@tusharsadhwani @asottile
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.