Skip to content

*: clone, resolve relative local URLs against CWD in CloneOptions.Validate#1891

Merged
pjbgf merged 1 commit into
go-git:mainfrom
AriehSchneier:fix-relative-clone-url
Apr 29, 2026
Merged

*: clone, resolve relative local URLs against CWD in CloneOptions.Validate#1891
pjbgf merged 1 commit into
go-git:mainfrom
AriehSchneier:fix-relative-clone-url

Conversation

@AriehSchneier

@AriehSchneier AriehSchneier commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

When a caller passes a URL like "../../some-repo" to Clone, the billy chroot-based FilesystemLoader rejects any path whose cleaned form starts with ".." ("chroot boundary crossed"), regardless of the chroot root.

Fix: in CloneOptions.Validate, detect local URLs whose cleaned form starts with ".." and resolve them to absolute paths via filepath.Abs before the URL reaches the transport layer. This matches the behaviour of git clone: relative paths are resolved against the caller's working directory at the command level, before any transport code runs.

Adds TestCloneOptionsValidate_RelativeDotDot as a regression test.

Note: This fix only applies to code paths that call CloneOptions.Validate (e.g., Repository.Clone). Direct calls to transport.NewEndpoint or transport.ParseURL will not have ../-relative paths normalized. A future PR may add normalization at the transport layer to cover all code paths.

Fixes: #1723

@AriehSchneier AriehSchneier force-pushed the fix-relative-clone-url branch 3 times, most recently from 18368d6 to f410dd2 Compare March 10, 2026 22:38
@AriehSchneier AriehSchneier marked this pull request as draft March 11, 2026 22:40
@AriehSchneier AriehSchneier marked this pull request as ready for review March 11, 2026 22:40
@AriehSchneier AriehSchneier force-pushed the fix-relative-clone-url branch 2 times, most recently from 0501e13 to a17004f Compare March 16, 2026 23:23
@AriehSchneier AriehSchneier requested a review from pjbgf March 16, 2026 23:33
@AriehSchneier AriehSchneier force-pushed the fix-relative-clone-url branch 8 times, most recently from 496c425 to a4e8d7e Compare March 23, 2026 23:00
Comment thread plumbing/transport/transport.go Outdated
@AriehSchneier AriehSchneier force-pushed the fix-relative-clone-url branch 7 times, most recently from 719bc65 to ad59a5b Compare March 31, 2026 00:43
@AriehSchneier AriehSchneier force-pushed the fix-relative-clone-url branch 3 times, most recently from cee6d69 to 13fd8bc Compare April 4, 2026 13:22
@AriehSchneier AriehSchneier force-pushed the fix-relative-clone-url branch 3 times, most recently from 6439da7 to b9ea6e8 Compare April 14, 2026 10:50
@AriehSchneier AriehSchneier force-pushed the fix-relative-clone-url branch 3 times, most recently from 222e215 to e4f9c97 Compare April 17, 2026 00:28
@AriehSchneier AriehSchneier force-pushed the fix-relative-clone-url branch 2 times, most recently from 96aa1ca to ec85b0e Compare April 26, 2026 06:38
@AriehSchneier

Copy link
Copy Markdown
Contributor Author

@pjbgf any chance you can review this again, save me rebasing it any more...

(PS the windows fail would probably be fixed by #1999 or #2001)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Resolves failures when cloning from ..-relative local paths (e.g. "../../repo") by normalizing such paths to absolute paths so the billy chroot-based filesystem loader does not reject them.

Changes:

  • Update CloneOptions.Validate to convert ..-relative local URLs into absolute filesystem paths.
  • Add a regression test asserting CloneOptions.Validate makes ..-relative URLs absolute.

Reviewed changes

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

File Description
options.go Normalizes ..-relative local clone URLs to absolute paths during CloneOptions.Validate.
options_test.go Adds regression coverage for CloneOptions.Validate handling of ..-relative URLs.

Comment thread options.go
Comment thread options.go Outdated
…ptions.Validate

When a caller passes a URL like "../../some-repo" to Clone, the billy chroot-based FilesystemLoader rejects any path whose cleaned form starts with ".." with "chroot boundary crossed".

Fix: in CloneOptions.Validate, detect local-endpoint paths whose clean form starts with ".." and resolve them to absolute paths via filepath.Abs before any transport code runs. This matches the behaviour of `git clone`: relative paths are resolved against the caller's working directory at the command level, before handing the URL to the transport layer.

Fixes: go-git#1723

Assisted-by: GitHub Copilot (claude-sonnet-4-6) <[email protected]>
Signed-off-by: Arieh Schneier <[email protected]>
@AriehSchneier AriehSchneier changed the title plumbing: transport, resolve ..-relative file URLs against CWD plumbing: clone, resolve ..-relative local URLs against CWD in CloneOptions.Validate Apr 28, 2026
@AriehSchneier AriehSchneier force-pushed the fix-relative-clone-url branch from 17d434c to 4b82051 Compare April 28, 2026 22:49
@pjbgf pjbgf changed the title plumbing: clone, resolve ..-relative local URLs against CWD in CloneOptions.Validate *: clone, resolve relative local URLs against CWD in CloneOptions.Validate Apr 29, 2026

@pjbgf pjbgf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@AriehSchneier thanks for working on this. 🙇

@pjbgf pjbgf merged commit 2bf1d08 into go-git:main Apr 29, 2026
19 checks passed
@AriehSchneier AriehSchneier deleted the fix-relative-clone-url branch April 30, 2026 00:46
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.

v6: Clone of parent fails (worked in v5)

3 participants