Skip to content

fix: disable sparse checkout cone mode to prevent root file leaks - #89

Closed
abnegate wants to merge 2 commits into
mainfrom
fix-sparse-cone
Closed

abnegate wants to merge 2 commits into
mainfrom
fix-sparse-cone

Conversation

@abnegate

@abnegate abnegate commented Apr 10, 2026 •

Copy link
Copy Markdown
Member

Important

This cannot merge here. utopia-php/vcs is a read-only mirror of the monorepo; development happens in packages/vcs. There is no monorepo PR carrying this change — nothing in the monorepo matches sparse — so if the fix is wanted it has to be reopened there.

The premise also needs rechecking before that happens. Git defaults to cone mode for git sparse-checkout init / set, which sets core.sparseCheckoutCone. This clone flow never calls either: it sets core.sparseCheckout true and appends the pattern to .git/info/sparse-checkout by hand (monorepo packages/vcs/src/VCS/Adapter/Git/GitHub.php:1226-1227, and the same in Bitbucket, GitLab and Gitea), which is legacy pattern mode. core.sparseCheckoutCone appears nowhere in packages/vcs on main. monorepo#252 reproduced this exact flow against real git and observed no root-file leak. The one scenario where this change would still matter is a runtime image whose system or global gitconfig sets core.sparseCheckoutCone = true — worth confirming against the Appwrite function-build image before reopening.

Status as of 2026-09-22: CONFLICTING against main (326 behind; generateCloneCommand was restyled and gained normalizeRepositoryPath in monorepo#252), Tests and Tests (External) failed on the head commit of 2026-04-10 and those logs have expired (HTTP 410), and both test-plan boxes are unticked. Only GitHub.php is changed, so the other three adapters would keep the old behaviour either way.

Summary

  • Git 2.37+ defaults to cone mode for sparse checkout, which always includes root-level files alongside the specified subdirectory
  • This causes VCS function deployments with a non-root providerRootDirectory to include root-level files (e.g. build.gradle.kts, package.json) that can break function builds
  • Affected since Appwrite 1.5.0 (ships Git 2.43.0), including Cloud (1.9.0 ships Git 2.52.0)
  • Fix: set core.sparseCheckoutCone false before writing the sparse-checkout pattern

Test plan

  • Existing testGenerateCloneCommand* tests pass (pattern * clones everything regardless of cone mode)
  • VCS deployment with nested providerRootDirectory no longer includes root-level files

@greptile-apps

greptile-apps Bot commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a regression in Git 2.37+ where cone mode for sparse checkout became the default, causing root-level files to always be included alongside the specified providerRootDirectory. The fix inserts git config core.sparseCheckoutCone false into the command sequence before the sparse-checkout pattern is written, but only when the target is a subdirectory (not the wildcard * pattern).

Confidence Score: 5/5

Safe to merge — targeted, minimal fix with no side effects on the wildcard (*) code path.

The change is small and surgical: one new boolean derived from an already-escaped variable, one conditional config command, and a cosmetic refactor of the array build. The $isSubdirectory comparison is correct ($rootDirectory is already escaped, so comparing against escapeshellarg('*') is the right approach). Cone mode is only disabled when it would actually cause a problem (specific subdirectory path), leaving the * path unaffected. No P1 or P0 findings.

No files require special attention.

Important Files Changed

Filename Overview
src/VCS/Adapter/Git/GitHub.php Adds core.sparseCheckoutCone false before writing the sparse-checkout pattern when a specific subdirectory is targeted, preventing Git 2.37+ cone-mode defaults from pulling in root-level files.

Reviews (2): Last reviewed commit: "(fix): only disable cone mode for subdir..." | Re-trigger Greptile

@abnegate abnegate added the test Enables E2E tests in CI/CD label Apr 10, 2026
@abnegate

Copy link
Copy Markdown
Member Author

Closing as obsolete. This repo is now a read-only mirror of appwrite/appwrite packages/vcs, and the clone flow (Git::cloneCommand) uses legacy sparse-checkout pattern mode (core.sparseCheckout + hand-written .git/info/sparse-checkout), never git sparse-checkout init/set. Reproduced against git 2.56.0 with root files plus a functions/a subdirectory: only functions/a was checked out with core.sparseCheckoutCone unset, true, false, and set globally to true — no root-file leak.

@abnegate abnegate closed this Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test Enables E2E tests in CI/CD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant