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 — git: add repository and remote archive support by aymanbagabas · Pull Request #2013 · go-git/go-git

Conversation

@aymanbagabas

@aymanbagabas aymanbagabas commented Apr 24, 2026

Copy link
Copy Markdown
Member

This implements the high level porcelain end of git-upload-archive and the git archive equivalent APIs. It adds a repo.Archive(opts) and git.ArchiveRemote(url, opts) methods to create archives of local and remote repositories.

This continues the work that was introduced in #1986

Sorry, something went wrong.

Uh oh!

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

All reactions
@aymanbagabas
aymanbagabas requested a review from pjbgf April 24, 2026 18:44
@aymanbagabas
aymanbagabas force-pushed the archive-git branch from 3fd5170 to f9a4d62 Compare April 24, 2026 19:00
aymanbagabas
aymanbagabas commented Apr 24, 2026
View reviewed changes
Comment thread archive_test.go
"github.com/stretchr/testify/require"
)

func TestArchiveRemote(t *testing.T) {

@aymanbagabas aymanbagabas Apr 24, 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.

We already test the remote transport logic in our git transport tests. This ensures the high-level API does validation.

Sorry, something went wrong.

Uh oh!

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

All reactions
@aymanbagabas
aymanbagabas force-pushed the archive-git branch from f9a4d62 to 0183df3 Compare April 27, 2026 15:19
pjbgf
pjbgf requested changes May 6, 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.

Overall, LGTM. Let's just tighten the validation on ArchiveOptions please as per comment below.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread repository.go
}

// Validate validates the ArchiveOptions.
func (o *ArchiveOptions) Validate() error {

@pjbgf pjbgf May 6, 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 add stricter rules here please, for example:

  • Format must be empty or one of tar, tar.gz, tgz, zip.
  • Prefix must be empty or a valid path component, not containing ...
  • Treeish must be a sha1/sha256 valid hex, or a valid heads name.
  • Paths must be empty, or a valid relative path not containing ...

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

@aymanbagabas aymanbagabas May 6, 2026 •
edited
Loading

Uh oh!

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

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.

Hey @pjbgf,

I made some changes to validate the treeish during git.Archive and before calling WriteArchive. The rules here are intentional for different reasons.

  • For Format, we do the validation in git.Archive because a remote server and git.ArchiveRemote can have different supported archive formats than local.
  • The Prefix here is the prepended prefix component added to the files being archived. Canonical git allows path components containing ../ and leave unsafe non-normalized prefixes to be the responsibility of the extractor. Many tar and unzip tools reject extracting to ../ by default.
  • Since we moved resolving the tree before actually calling WriteArchive, we validate the tree is valid and has either valid sha1/sha256 or valid heads.
  • Paths are just filters, if a path doesn't exist, we already return pathspec did not match any files similar to canonical git. This validation cannot happen during Validate without resolving the tree and start writing the archive.

Sorry, something went wrong.

Uh oh!

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

All reactions

@aymanbagabas aymanbagabas May 9, 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.

@pjbgf Prefix now rejects paths with .. components and absolute paths.

Sorry, something went wrong.

Uh oh!

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

All reactions
Copilot AI review requested due to automatic review settings May 6, 2026 14:19
@aymanbagabas
aymanbagabas force-pushed the archive-git branch from 0183df3 to 4ef6487 Compare May 6, 2026 14:19
Copilot started reviewing on behalf of aymanbagabas May 6, 2026 14:19
View session
Copilot AI reviewed May 6, 2026
View reviewed changes

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.

Pull request overview

Adds porcelain-level archive creation APIs to the git package, enabling git archive-like behavior for local repositories and git archive --remote-like behavior via git-upload-archive, building on the existing transport-layer support.

Changes:

  • Introduces Repository.Archive(opts) / Repository.ArchiveContext(ctx, opts) for streaming local repository archives.
  • Adds ArchiveRemote(url, opts) / ArchiveRemoteContext(ctx, url, opts) to request archives from remote repositories using git-upload-archive.
  • Refactors internal archive generation to resolve tree-ish metadata separately and expands tests around formats/prefix/path filtering.
Show a summary per file
File Description
repository.go Adds ArchiveOptions and local repository archive streaming APIs.
archive.go Adds remote archive entrypoints that handshake and invoke git-upload-archive.
internal/archive/archive.go Refactors archive generation API to accept a resolved tree + commit metadata; adds ErrUnsupportedFormat.
plumbing/transport/upload_archive.go Updates server-side UploadArchive to resolve tree-ish before writing the archive.
repository_test.go Adds coverage for local repository archive generation (formats/prefix/path filtering/cancellation).
archive_test.go Adds unit tests for ArchiveOptions.Validate and basic ArchiveRemote argument/validation behavior.

Copilot's findings

Comments suppressed due to low confidence (1)

archive_test.go:122

  • These parallel subtests capture the range variable tt. Since tt is reused across iterations, t.Parallel() can lead to subtests using the wrong url/options/wantErr values. Rebind tt := tt (or switch to an index loop) before t.Run.
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			t.Parallel()
			_, err := ArchiveRemote(tt.url, tt.opts)
  • Files reviewed: 6/6 changed files
  • Comments generated: 6

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread repository_test.go Resolved

Uh oh!

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

Comment thread archive_test.go Resolved

Uh oh!

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

Comment thread archive.go
Comment on lines +58 to +61
return arch.Archive(ctx, &transport.ArchiveRequest{
Args: args,
Progress: o.Progress,
})
Comment thread archive.go Resolved

Uh oh!

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

Comment thread archive.go Resolved

Uh oh!

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

Comment thread repository.go Resolved

Uh oh!

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

@aymanbagabas
aymanbagabas requested a review from pjbgf May 6, 2026 14:31
@pjbgf pjbgf mentioned this pull request May 6, 2026
Align object encoding with upstream #2066
Merged
@aymanbagabas
aymanbagabas force-pushed the archive-git branch 2 times, most recently from 5924d14 to 9293937 Compare May 9, 2026 18:00
@aymanbagabas
aymanbagabas requested a review from Copilot May 9, 2026 18:02
@aymanbagabas
aymanbagabas force-pushed the archive-git branch from 9293937 to 4ee8db2 Compare May 9, 2026 18:02
Copilot started reviewing on behalf of aymanbagabas May 9, 2026 18:02
View session
@aymanbagabas
aymanbagabas force-pushed the archive-git branch from 4ee8db2 to 6dea73c Compare May 9, 2026 18:02
Copilot AI reviewed May 9, 2026
View reviewed changes

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's findings

  • Files reviewed: 6/6 changed files
  • Comments generated: 7

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread archive.go Resolved

Uh oh!

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

Comment thread archive.go Resolved

Uh oh!

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

Comment thread repository.go Resolved

Uh oh!

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

Comment thread repository.go Resolved

Uh oh!

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

Comment thread repository_test.go Resolved

Uh oh!

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

Comment thread archive_test.go Resolved

Uh oh!

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

Comment thread internal/archive/archive.go Resolved

Uh oh!

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

@aymanbagabas
aymanbagabas force-pushed the archive-git branch from 6dea73c to 57a94dc Compare May 9, 2026 18:23
@aymanbagabas
aymanbagabas requested a review from Copilot May 9, 2026 18:23
Copilot started reviewing on behalf of aymanbagabas May 9, 2026 18:23
View session
@aymanbagabas
aymanbagabas force-pushed the archive-git branch from 57a94dc to d8480cf Compare May 9, 2026 18:24
Copilot AI reviewed May 9, 2026
View reviewed changes

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's findings

  • Files reviewed: 7/7 changed files
  • Comments generated: 7

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread repository.go Resolved

Uh oh!

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

Comment thread repository.go Resolved

Uh oh!

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

Comment thread archive.go Resolved

Uh oh!

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

Comment thread archive.go Resolved

Uh oh!

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

Comment thread plumbing/transport/pack_stream.go Resolved

Uh oh!

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

Comment thread archive_test.go
Comment on lines +117 to +121
name: "remote allows custom format",
url: "file:///tmp/repo.git",
opts: &ArchiveOptions{Format: "tar.xz", Treeish: "master"},
wantErr: "",
},

@aymanbagabas aymanbagabas May 9, 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.

File here is the transport and our client resolved the url to our default file transport. Custom transports can be added via ClientOptions. If a transport is not supported or valid, we error during the construction of client.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread archive_test.go Resolved

Uh oh!

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

@aymanbagabas
aymanbagabas force-pushed the archive-git branch 2 times, most recently from ff3e445 to c1dafd7 Compare May 9, 2026 18:34
@aymanbagabas
aymanbagabas requested a review from Copilot May 9, 2026 18:34
Copilot started reviewing on behalf of aymanbagabas May 9, 2026 18:35
View session
Copilot AI reviewed May 9, 2026
View reviewed changes

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's findings

Comments suppressed due to low confidence (2)

archive_test.go:136

  • The subtests run with t.Parallel() but capture the range variable tt from the outer loop. Rebind tt := tt inside the loop before t.Run to avoid all subtests using the last case / racing.
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			t.Parallel()
			_, err := ArchiveRemote(tt.url, tt.opts)
			if tt.wantErr == "" {

archive_test.go:213

  • The subtests run with t.Parallel() but capture the range variable tt from the outer loop. Rebind tt := tt inside the loop before t.Run (this also ensures each subtest uses the intended tt.opts pointer).
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			t.Parallel()

			rc, err := ArchiveRemote(repoURL, tt.opts)
			require.NoError(t, err)
  • Files reviewed: 7/7 changed files
  • Comments generated: 5

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread repository.go Resolved

Uh oh!

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

Comment thread repository_test.go Resolved

Uh oh!

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

Comment thread repository_test.go Resolved

Uh oh!

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

Comment thread archive_test.go Resolved

Uh oh!

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

Comment thread archive_test.go
Comment on lines +151 to +156
base := t.TempDir()
repoFS := test.PrepareRepository(t, fixtures.Basic().One(), base, "basic.git")
repoPath, err := filepath.Abs(repoFS.Root())
require.NoError(t, err)
repoURL := "file://" + repoPath

@aymanbagabas
aymanbagabas force-pushed the archive-git branch from c1dafd7 to 14c685e Compare May 9, 2026 18:45
@aymanbagabas
git: add repository and remote archive support
104343e
Signed-off-by: Ayman Bagabas <[email protected]>
@aymanbagabas
aymanbagabas force-pushed the archive-git branch from 14c685e to 104343e Compare May 9, 2026 18:47
pjbgf
pjbgf reviewed May 12, 2026
View reviewed changes
Comment thread archive.go Resolved

Uh oh!

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

pjbgf
pjbgf reviewed May 12, 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.

Tiny nit on defer sess.Close(). Apart from that, please rebase it.

Sorry, something went wrong.

Uh oh!

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

All reactions
pjbgf
pjbgf approved these changes May 13, 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 working on this. 🙇

Sorry, something went wrong.

Uh oh!

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

All reactions
@pjbgf
pjbgf merged commit 5f8076d into go-git:main May 13, 2026
17 checks passed

Uh oh!

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

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

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.