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 — plumbing: transport, add git-upload-archive support by aymanbagabas · Pull Request #1986 · go-git/go-git

Conversation

@aymanbagabas

@aymanbagabas aymanbagabas commented Apr 13, 2026

Copy link
Copy Markdown
Member

This PR adds support for the git-upload-archive service to the transport layer, allowing fetching of archives from remote git repositories over SSH, HTTP, and local file transports.

Background

The git-upload-archive protocol command is used by git archive --remote to fetch archives from remote repositories without cloning them. This is useful for CI/CD pipelines, release automation, and tools that need specific files from a repo.

Changes

Client-Side Types

Archiver interface - Sessions that implement this can perform archive operations:

type Archiver interface {
    Archive(ctx context.Context, req *ArchiveRequest) (io.ReadCloser, error)
}

ArchiveRequest - Client archive request:

  • Args []string: arguments sent as "argument " pkt-lines (format, prefix, tree-ish, paths)
  • Progress sideband.Progress: optional progress callback for status messages

Server-Side Types

UploadArchiveRequest - Server archive request configuration:

  • AllowUnreachable bool: disables security restrictions allowing arbitrary refs

UploadArchive function - Server-side handler for the git-upload-archive protocol.

Backend Support

SSH/TCP/Unix transports - Backend now dispatches to UploadArchive:

case transport.UploadArchiveService:
    return transport.UploadArchive(...)

HTTP - Left for future protocol-v2 work (HTTP archive requires command-based protocol)

Wire Protocol

Implements the git-upload-archive protocol:

  • Client sends "argument " pkt-lines for format, prefix, tree-ish, etc.
  • Server sends "ACK" or "NACK "
  • Archive data streamed via sideband (channel 1 = data, channel 2 = progress)

Supported Formats

Supported formats parsed from args:

  • tar, tar.gz, tgz, zip
  • --prefix=path/ adds prefix to archive entries
  • --list lists available archives
  • Tree-ish (commit, tag, branch) specifies what to archive

Testing

  • TestArchive_Tar, TestArchive_TarGz, TestArchive_Zip (file transport)
  • TestGitTransport_Archive (git daemon transport)
  • TestSSHTransport_Archive (SSH transport)

All tests verify archive contents against git's output.

Security

The uploadArchive.allowUnreachable config option controls whether arbitrary SHA-1 expressions are allowed. By default, only ref targets (e.g., v1.0, main) and ref:path sub-tree syntax are allowed.

Follow-up Work

A future PR will add porcelain-level support:

  • git.Archive() convenience method
  • ArchiveOptions with parametrized fields:
    • Format: tar, tar.gz, zip
    • Prefix: prefix path for archive entries
    • Remote: tree-ish reference to archive
    • Paths: optional path filter
    • Additional git archive --remote flags

Usage Example

sess, _ := client.Dial("[email protected]:go-git/go-git.git")
req := &transport.ArchiveRequest{
    Args: []string{"--format=tar.gz", "--prefix=go-git/", "v5.12.0"},
}
rc, _ := sess.Archive(ctx, req)
defer rc.Close()
// Write rc to file or pipe to tar/gzip

Supersedes: #1985

Sorry, something went wrong.

Uh oh!

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

All reactions
@aymanbagabas
aymanbagabas requested review from Copilot and pjbgf April 13, 2026 15:01
Copilot AI reviewed Apr 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sorry, something went wrong.

Uh oh!

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

All reactions
aymanbagabas
aymanbagabas commented Apr 13, 2026
View reviewed changes
Comment thread plumbing/transport/upload_archive.go Outdated
Comment on lines +27 to +36
// AllowUnreachable when true disables the default security restrictions
// and allows clients to use arbitrary SHA-1 expressions. By default,
// only direct ref targets (e.g. v1.0, main) and ref:path sub-tree
// syntax (e.g. v1.0:Documentation) are allowed.
//
// This serves as the default value. When the repository-level config
// uploadArchive.allowUnreachable is explicitly set, it always overrides
// this value (both true → false and false → true).
// See https://git-scm.com/docs/git-upload-archive
AllowUnreachable bool

@aymanbagabas aymanbagabas Apr 13, 2026

Copy link
Copy Markdown
Member Author

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.

This is usually derived from global/system config then overridden by repository config. Alternatively, we'd use config.LoadConfig.

cc/ @pjbgf

Sorry, something went wrong.

Uh oh!

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

All reactions

@pjbgf pjbgf Apr 14, 2026

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.

Let's start with the current cfg, err := st.Config() which is already in place. As that's the safest approach to start with.

Sorry, something went wrong.

Uh oh!

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

All reactions

@aymanbagabas aymanbagabas Apr 15, 2026

Copy link
Copy Markdown
Member Author

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.

Cool, I will drop this option and add a comment to investigate this later and derive it from global/system config before repository config.

Sorry, something went wrong.

Uh oh!

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

pjbgf reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
pjbgf
pjbgf requested changes Apr 14, 2026
View reviewed changes

@pjbgf pjbgf 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.

@aymanbagabas thanks for looking into this, here's some feedback:

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread plumbing/transport/upload_archive.go Outdated
Comment on lines +27 to +36
// AllowUnreachable when true disables the default security restrictions
// and allows clients to use arbitrary SHA-1 expressions. By default,
// only direct ref targets (e.g. v1.0, main) and ref:path sub-tree
// syntax (e.g. v1.0:Documentation) are allowed.
//
// This serves as the default value. When the repository-level config
// uploadArchive.allowUnreachable is explicitly set, it always overrides
// this value (both true → false and false → true).
// See https://git-scm.com/docs/git-upload-archive
AllowUnreachable bool

@pjbgf pjbgf Apr 14, 2026

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.

Let's start with the current cfg, err := st.Config() which is already in place. As that's the safest approach to start with.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread plumbing/transport/upload_archive.go Resolved

Uh oh!

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

Comment thread plumbing/transport/upload_archive.go Resolved

Uh oh!

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

Comment thread plumbing/transport/upload_archive.go Resolved

Uh oh!

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

Comment thread plumbing/transport/upload_archive.go Outdated
return (mode | 0o777) &^ defaultUmask
}

func writeTarArchive(st storage.Storer, w io.Writer, tree *object.Tree, prefix string, pathFilter []string, modTime time.Time) error {

@pjbgf pjbgf Apr 14, 2026

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.

I think we are missing this:

Additionally the commit ID is stored in a global extended pax header if the tar format is used; it can be extracted using git get-tar-commit-id. In ZIP files it is stored as a file comment.

Sorry, something went wrong.

Uh oh!

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

aymanbagabas reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread plumbing/transport/upload_archive.go Resolved

Uh oh!

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

Comment thread plumbing/transport/upload_archive.go Resolved

Uh oh!

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

@aymanbagabas
aymanbagabas force-pushed the transport-archive branch from 73b8fc0 to 174aa08 Compare April 15, 2026 03:20
@aymanbagabas
aymanbagabas requested a review from pjbgf April 15, 2026 03:29
@aymanbagabas
aymanbagabas force-pushed the transport-archive branch 2 times, most recently from 5ef59da to cebfcdd Compare April 16, 2026 00:08
pjbgf
pjbgf reviewed Apr 23, 2026
View reviewed changes
Comment thread internal/archive/archive.go Resolved

Uh oh!

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

@aymanbagabas
aymanbagabas force-pushed the transport-archive branch from 8106cd2 to 6fa62ef Compare April 24, 2026 00:59
aymanbagabas and others added 19 commits April 24, 2026 15:28
@aymanbagabas @pjbgf
plumbing: transport, add support for git-upload-archive
4b02cf5
Add git-upload-archive service support to transport layer. This allows
fetching archives (tarballs) from remote git repositories over various
transports (SSH, HTTP, and local file).

Expose new Archivable interface via transport.Session and implement:
- ArchiveRequest type for archive configuration (format, compression, prefix)
- UploadArchiveRequest/UploadArchive types for wire protocol
- Support for archive filters (tree and commit filters)
- Backend dispatch for SSH/TCP/Unix transports
- Tests for file, git, and SSH transports

HTTP backend support left for future protocol-v2 work.
@aymanbagabas @pjbgf
plumbing: transport, preserve file permissions in git-upload-archive
b95357e
The previous implementation was losing file permission details by converting
all files to either 0o644 or 0o755, discarding the actual git mode bits
including group-writable.

Added applyUmask() functions that extract Unix permission bits from the
git mode and apply the default umask (0o002) following canonical git's
tar.umask behavior. This preserves the original file permissions from
the tree being archived.

Also added tests to verify file permissions are correctly preserved in
both tar and zip archives.
@aymanbagabas @pjbgf
plumbing: transport, support space-separated args and respect treeish…
6690d3c
… position for paths
@aymanbagabas @pjbgf
plumbing: transport, drop allowUnreachable option
7b3bb62
@aymanbagabas @pjbgf
plumbing: transport, add comment about git archive with trees
287273b
@aymanbagabas @pjbgf
plumbing: transport, archive: include commit ID in tar/zip archives a…
6f4d3d3
…nd tests
@aymanbagabas @pjbgf
plumbing: transport, archive: add error for pathspec with no matches
e0ea3ae
@aymanbagabas @pjbgf
plumbing: transport, archive: refactor archive code into internal/arc…
47b9e38
…hive
@aymanbagabas @pjbgf
plumbing: archive, add tests for path filter matching and ref resolution
96e9d8b
@aymanbagabas @pjbgf
plumbing: transport, archive: add test cases for nested paths
5e54d82
@aymanbagabas @pjbgf
plumbing: transport, archive: add allowUnreachable security tests
63c1825
@aymanbagabas @pjbgf
internal: archive, fix lint and parallelize tests
7683326
@aymanbagabas @pjbgf
internal: archive, test: suppress parallel test warnings for tests th…
e521fdc
…at rely on shared fixture state
@pjbgf
plumbing: transport, add annotated tags support for git-upload-archive
9b69c9c
Signed-off-by: Paulo Gomes <[email protected]>
@pjbgf
plumbing: transport, Explicit errors for unsupported archive args
8732362
Signed-off-by: Paulo Gomes <[email protected]>
@pjbgf
plumbing: transport, Fix linter issue
fe61e15
Signed-off-by: Paulo Gomes <[email protected]>
@pjbgf
plumbing: transport, Remove support for unreachable
7df71e6
Signed-off-by: Paulo Gomes <[email protected]>
@pjbgf
plumbing: transport, Reject oversized symlinks
362d653
Signed-off-by: Paulo Gomes <[email protected]>
@pjbgf
plumbing: transport, Add prefix validation
4928734
Signed-off-by: Paulo Gomes <[email protected]>
@pjbgf
pjbgf force-pushed the transport-archive branch from 6fa62ef to 4928734 Compare April 24, 2026 14:28
@pjbgf
plumbing: transport, Handle archive errors
ce1e0f0
Signed-off-by: Paulo Gomes <[email protected]>
pjbgf
pjbgf approved these changes Apr 24, 2026
View reviewed changes

@pjbgf pjbgf 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.

@aymanbagabas thanks for the great effort putting this together. 🙇🙇🙇

Sorry, something went wrong.

Uh oh!

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

aymanbagabas reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@pjbgf
pjbgf merged commit 5b47ae8 into go-git:main Apr 24, 2026
16 checks passed

Uh oh!

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

@aymanbagabas aymanbagabas mentioned this pull request Apr 24, 2026
git: add repository and remote archive support #2013
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@pjbgf pjbgf pjbgf approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

None yet

Projects

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.

3 participants

@aymanbagabas @pjbgf
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 01402775 — 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.