Skip to content

Fix IndexMatchedPath callback to not panic on empty pathspec#1273

Open
ehuss wants to merge 1 commit into
rust-lang:mainfrom
ehuss:empty-pathspec-add-all-empty-slice
Open

Fix IndexMatchedPath callback to not panic on empty pathspec#1273
ehuss wants to merge 1 commit into
rust-lang:mainfrom
ehuss:empty-pathspec-add-all-empty-slice

Conversation

@ehuss

@ehuss ehuss commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

When given an empty set of pathspecs or a set with an empty string is used, the matched pathspec in the IndexMatchedPath ends up being null. Instead of panicking, use an empty slice to mean the "all" pathspec.

git has forbidden empty pathspecs since 2.16 (from 2018), but it looks like libgit2 hasn't followed that change.

One could argue that getting an empty pathspec isn't quite the same as an empty set of pathspecs, but since they are treated the same (and you can't distinguish between them), it seems reasonable to me to just use an empty slice to mean the same.

The main risk is if libgit2 ever decides that the empty string is no longer allowed, but an empty set is. I'm not sure if that would ever happen.

When given an empty set of pathspecs or a set with an empty string is
used, the matched pathspec in the IndexMatchedPath ends up being null.
Instead of panicking, use an empty slice to mean the "all" pathspec.

git has forbidden empty pathspecs since 2.16 (from 2018), but it looks
like libgit2 hasn't followed that change.

One could argue that getting an empty pathspec isn't quite the same as
an empty set of pathspecs, but since they are treated the same (and you
can't distinguish between them), it seems reasonable to me to just use
an empty slice to mean the same.

The main risk is if libgit2 ever decides that the empty string is no
longer allowed, but an empty set is. I'm not sure if that would ever
happen.
@rustbot rustbot added the S-waiting-on-review Status: Waiting on review label Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Waiting on review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants