Skip to content

Conversation

@Frederick888
Copy link

@Frederick888 Frederick888 commented Sep 13, 2025

a7b1d11ab refs: Handle normalizing negative refspecs

Upstream commit 2adb7bc.

Negative refspecs were added in Git v2.29.0 which allows refspecs to be
prefixed with ^1. Currently, the library is unable to normalize
negative refspecs which causes errors in different tools that rely on
libgit2. Specifically, when the library attempts to parse and
normalize a negative refspec, it returns a GIT_EINVALIDSPEC code.

Add the ability to correctly normalize negative refspecs. While this PR
will not update the behavior of fetch, or other actions that rely on
negative refspecs, this allows us to be able to successfully parse and
normalize them. A future change will handle updating the individual
actions.

383be7b53 refspec: Add func to distinguish negative refspecs

Upstream commit 3d9f406.

Negative refspecs were added in Git v2.29.0 and are denoted by prefixing
a refspec with a caret. This adds a way to distinguish if a refspec is
negative and match negative refspecs.

20f77fb55 remote: Handle fetching negative refspecs

Upstream commit f7f30ec.

Add support for fetching with negative refspecs. Fetching from the
remote with a negative refspec will now validate any references fetched
do not match any negative refspecs and at least one non-negative
refspec. As we must ensure that fetched references do not match any of
the negative refspecs provided, we cannot short-circuit when checking
for matching refspecs.

Closes romkatv/gitstatus#438

Footnotes

  1. https://github.com/git/git/commit/c0192df6306d4d9ad77f6015a053925b13155834

Upstream commit 2adb7bc.

Negative refspecs were added in Git v2.29.0 which allows refspecs to be
prefixed with `^`[^1]. Currently, the library is unable to normalize
negative refspecs which causes errors in different tools that rely on
`libgit2`. Specifically, when the library attempts to parse and
normalize a negative refspec, it returns a `GIT_EINVALIDSPEC` code.

Add the ability to correctly normalize negative refspecs. While this PR
will not update the behavior of `fetch`, or other actions that rely on
negative refspecs, this allows us to be able to successfully parse and
normalize them. A future change will handle updating the individual
actions.

[^1]: git/git@c0192df
Upstream commit 3d9f406.

Negative refspecs were added in Git v2.29.0 and are denoted by prefixing
a refspec with a caret. This adds a way to distinguish if a refspec is
negative and match negative refspecs.
Upstream commit f7f30ec.

Add support for fetching with negative refspecs. Fetching from the
remote with a negative refspec will now validate any references fetched
do not match _any_ negative refspecs and at least one non-negative
refspec. As we must ensure that fetched references do not match any of
the negative refspecs provided, we cannot short-circuit when checking
for matching refspecs.
@Frederick888 Frederick888 marked this pull request as ready for review September 13, 2025 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Negative fetch refspec breaks gitstatus

1 participant