Skip to content

[v5] git: Add strict checks for supported extensions#1861

Merged
pjbgf merged 2 commits intogo-git:releases/v5.xfrom
pjbgf:backport-checks
Feb 24, 2026
Merged

[v5] git: Add strict checks for supported extensions#1861
pjbgf merged 2 commits intogo-git:releases/v5.xfrom
pjbgf:backport-checks

Conversation

@pjbgf
Copy link
Member

@pjbgf pjbgf commented Feb 23, 2026

The upstream Git enforces fail-safe heuristics to ensure that older git versions will avoid handling repositories using extensions they are unaware of.

The logic is largely based on the value of core.repositoryformatversion. As per official Git docs:

This version specifies the rules for operating on the on-disk repository data.
An implementation of git which does not understand a particular version
advertised by an on-disk repository MUST NOT operate on that repository;
doing so risks not only producing wrong results, but actually losing data.

Now go-git will ensure that:

  • The git.Open logic will verify and enforces the extension support rules.
  • go-git will keep track of built-in extensions that it supports.

This is a breaking change and it will force go-git to not be able to open repositories that it in fact doesn't really support. Conversaly, the error messages will be more useful (e.g. unknown extension: X vs object not found).

Upstream refs:

Back-port of #1850.

The upstream Git enforces fail-safe heuristics to ensure that older git versions
will avoid handling repositories using extensions they are unaware of.

The logic is largely based on the value of core.repositoryformatversion. As per
official Git docs:
> This version specifies the rules for operating on the on-disk repository data.
> An implementation of git which does not understand a particular version
> advertised by an on-disk repository MUST NOT operate on that repository;
> doing so risks not only producing wrong results, but actually losing data.

Now go-git will ensure that:
- The git.Open logic will verify and enforces the extension support rules.
- go-git will keep track of built-in extensions that it supports.

This is a breaking change and it will force go-git to not be able to open
repositories that it in fact doesn't really support. Conversaly, the error
messages will be more useful (e.g. unknown extension vs object not found).

Upstream refs:
- https://git-scm.com/docs/git-config#Documentation/git-config.txt-extensions
- https://git-scm.com/docs/gitrepository-layout#_git_repository_format_versions

Signed-off-by: Paulo Gomes <[email protected]>
@pjbgf pjbgf marked this pull request as ready for review February 24, 2026 12:08
Copilot AI review requested due to automatic review settings February 24, 2026 12:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR backports strict Git extension validation from #1850 to go-git v5. It enforces Git's fail-safe heuristics for repository format versions, ensuring go-git refuses to open repositories using unsupported extensions or format versions.

Changes:

  • Added extension validation logic in verifyExtensions() function that checks repository format version compatibility
  • Integrated extension checks into the Open() function to reject unsupported repositories early
  • Added comprehensive test coverage for various extension and format version scenarios

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
repository_extensions.go New file implementing core extension validation logic with error definitions, supported extension maps, and the verifyExtensions function
repository.go Integrates extension validation into the Open function by calling verifyExtensions after loading config
repository_extensions_test.go New test file with table-driven tests covering various extension and format version scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

The test workflow for v5 diverged from main slightly, including its
job name, which caused it to not be in-sync with the latest repository
rulesets.

Signed-off-by: Paulo Gomes <[email protected]>
@pjbgf pjbgf merged commit c7b5960 into go-git:releases/v5.x Feb 24, 2026
12 checks passed
@pjbgf pjbgf deleted the backport-checks branch February 24, 2026 12:35
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.

2 participants