Skip to content

git: submodule, Add relative URL regression tests#2072

Merged
pjbgf merged 1 commit into
go-git:mainfrom
hiddeco:submodule-relative-url-regression
May 7, 2026
Merged

git: submodule, Add relative URL regression tests#2072
pjbgf merged 1 commit into
go-git:mainfrom
hiddeco:submodule-relative-url-regression

Conversation

@hiddeco

@hiddeco hiddeco commented May 7, 2026

Copy link
Copy Markdown
Member

Reported by @N0zoM1z0, thank you! 🙇


Mirror the v5 fix from PR #2070 (54a3234) to v6 as regression coverage. The v5 fix corrected Submodule.Repository() to resolve relative submodule URLs such as ../X.git against the parent remote URL per git-submodule(1)1 and canonical Git, rather than absolutizing them against the process CWD.

The v5 root cause — transport.NewEndpoint running scheme-less inputs through parseFile, which called filepath.Abs — does not exist on v6: internal/url.ParseFile stores the input verbatim, so the relative-resolution branch in
Submodule.Repository() already fires correctly. These tests lock that invariant in so a future refactor reintroducing eager normalization in ParseFile fails loudly instead of silently breaking submodule resolution.

Five tests cover relative URLs against HTTPS and SSH parents, deep traversal (../../), absolute local URL preservation, and the no-parent-remote case. The last asserts an explicit error; v6 still had the unguarded remotes[0] access that PR #2070 replaced, so port the matching guard alongside the tests.

Comment thread submodule_test.go Outdated
@hiddeco hiddeco force-pushed the submodule-relative-url-regression branch 2 times, most recently from 8351a85 to 79874d1 Compare May 7, 2026 13:08
pjbgf
pjbgf previously approved these changes May 7, 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.

@hiddeco thanks for working on this. 🙇

Mirror the regression-test coverage from v5 PR go-git#2070 (54a3234)
to v6. The v5 commit fixed `Submodule.Repository()` to resolve
relative submodule URLs such as `../X.git` against the parent
repository's remote URL per git-submodule(1)[1] and canonical
Git, rather than absolutizing them against the process CWD.

The v5 root cause — `transport.NewEndpoint` running scheme-less
inputs through `parseFile`, which called `filepath.Abs` — does
not exist on v6: `internal/url.ParseFile` stores the input
verbatim. The relative-resolution branch in
`Submodule.Repository()` therefore already fires correctly, and
PR go-git#2071 (0d02124) plus PR go-git#2076 (1655810) further hardened
remote selection via `defaultRemote` and `lookupRemote`. So the
production code on v6 already has the fix; this commit only
backfills the matching test coverage so a future refactor that
reintroduces eager normalization in `ParseFile` fails loudly
instead of silently breaking submodule resolution.

Five table-driven cases cover relative URLs against HTTPS and
SSH parents, deep traversal (`../../`), absolute local URL
preservation, and the no-parent-remote case. The last asserts
the `defaultRemote`-wrapped error
`resolving relative submodule URL: remote "origin" not found`,
matching v5's `TestRepositoryRelativeURLNoParentRemote` after
the same upstream remote-selection refactor landed there.

[1]: https://git-scm.com/docs/git-submodule

Assisted-by: Claude Opus 4.7
Signed-off-by: Hidde Beydals <[email protected]>
@hiddeco hiddeco force-pushed the submodule-relative-url-regression branch from 79874d1 to 0964dd8 Compare May 7, 2026 13:16

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

@hiddeco Thanks for working on this. 🙇

@pjbgf pjbgf merged commit b837899 into go-git:main May 7, 2026
17 checks passed
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