Skip to content

Fix GitLab adapter treating './' as a literal path instead of repository root#121

Merged
HarshMN2345 merged 4 commits into
mainfrom
fix/gitlab-root-directory-path
Jul 22, 2026
Merged

Fix GitLab adapter treating './' as a literal path instead of repository root#121
HarshMN2345 merged 4 commits into
mainfrom
fix/gitlab-root-directory-path

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Jul 22, 2026

Copy link
Copy Markdown
Member

Summary

GitLab's repository/tree and repository/files/:path endpoints receive path as a literal query parameter / URL segment value, which — unlike GitHub's contents API, where the path is a URI path segment subject to standard dot-segment normalization (RFC 3986 §6.2.2.3) — is never normalized. A caller passing './' or '.' to mean "repository root" (the conventional meaning in git/POSIX shells, and what GitHub's adapter tolerates transparently) gets an empty tree or a 404 from GitLab instead, because GitLab looks for a file/directory literally named ..

Confirmed empirically: traced a real console request through to the raw value received (./, 2 bytes, no encoding artifacts) before concluding this belongs in the adapter rather than being worked around by every caller.

Changes

  • Added GitLab::normalizeRepositoryPath(): treats './'/'.' as repository root (empty path) and strips a leading './' from nested paths.
  • Applied it in listRepositoryContents() and getRepositoryContent().
  • Added regression tests: testListRepositoryContentsRootSentinels (asserts '', '.', './' all return the same root listing) and testGetRepositoryContentRootSentinelPrefix (asserts 'README.md' and './README.md' fetch the same file).

Test plan

  • composer lint (Pint) clean.
  • composer check (PHPStan level 8) clean.
  • CI integration tests against the real GitLab service (tests.yml).

… repository root

GitLab's tree/file endpoints receive path as a literal query parameter
or URL segment value, which is never subject to URI dot-segment
normalization the way GitHub's contents API path segments are. Callers
that pass './' or '.' to mean "repository root" (as is conventional in
git and POSIX shells) get an empty tree / 404 instead of root contents,
since GitLab looks for a file/directory literally named '.'.

Normalize './' and '.' to an empty root path, and strip a leading './'
from nested paths, in both listRepositoryContents() and
getRepositoryContent().
@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes GitLab repository paths that use dot segments to represent the repository root. The main changes are:

  • Adds centralized repository-path normalization.
  • Applies normalization to file retrieval and directory listings.
  • Tests root sentinels, repeated relative prefixes, and redundant nested segments.

Confidence Score: 5/5

This looks safe to merge.

  • The repeated relative-prefix failure is fixed.
  • The new tests cover both file retrieval and repository listings.
  • No blocking issue remains in the changed code.

Important Files Changed

Filename Overview
src/VCS/Adapter/Git/GitLab.php Normalizes empty and dot path segments before GitLab file and tree requests.
tests/VCS/Adapter/GitLabTest.php Adds tests for root sentinels, repeated relative prefixes, and redundant nested path segments.

Reviews (4): Last reviewed commit: "Rewrite normalization as path-segment fi..." | Re-trigger Greptile

Comment thread src/VCS/Adapter/Git/GitLab.php Outdated
'./././' was only stripped once, leaving a literal './' that GitLab
would still look up as-is. Loop the strip and collapse a leftover
'.' to root too.
…tripping

The leading-'./' loop only handled prefixes; it left embedded dot
segments (src/./main.php), double slashes (src//main.php), and
trailing slashes untouched, all of which GitLab still resolves
literally. Filter empty and '.' segments out of the whole path instead
of special-casing the start of the string.
@HarshMN2345
HarshMN2345 requested a review from Meldiron July 22, 2026 10:09
@HarshMN2345
HarshMN2345 merged commit 37580b1 into main Jul 22, 2026
10 of 13 checks passed
HarshMN2345 added a commit to appwrite/appwrite that referenced this pull request Jul 22, 2026
utopia-php/vcs 4.4.4 (utopia-php/vcs#121) fixes the root cause in the
GitLab adapter itself: './', '.', embedded dot segments, and double
slashes are now normalized before hitting GitLab's API. The endpoint-
level normalization added here as a stopgap is no longer needed and
is reverted.
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