fix(git): gate git-lfs auto-install on provisioned hosts, matching ensureGit - #828
Conversation
Plain git never installs missing tools on your behalf: with no LFS filter available it just leaves pointer stubs, silently. SetupLFS diverged from that by trying to apt/GitHub-release install git-lfs on every clone, which only ever fails in unprivileged environments and adds noisy permission-denied logs plus a wasted network round trip. Drop the install attempt so devsy matches git's own default behavior: use git-lfs when it's already present, fall back to pointer stubs when it's not.
✅ Deploy Preview for devsydev canceled.
|
📝 WalkthroughWalkthroughGit and Git LFS installation behavior is now controlled by agent locality. Local agents avoid installation, while remote agents retain Git installation and permit LFS installation during cloning. ChangesLocal Agent Git and LFS Installation Control
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Workspace
participant GitClone
participant Repo
participant LFS
Workspace->>GitClone: build options from agent configuration
GitClone->>Repo: clone with allowLFSInstall
Repo->>LFS: SetupLFS(mode, allowLFSInstall)
LFS-->>Repo: skip or perform git-lfs installation
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ Deploy Preview for images-devsy-sh canceled.
|
Reinstate git-lfs auto-install, but only where devsy.ensureGit already draws the same line for the git binary itself: devsy-provisioned remote hosts it controls, never a user's local environment. Adds WithAllowLFSInstall/SetupLFS(..., allowInstall) so the decision is made once at the call site (mirroring ensureGit's isLocalAgent check) instead of unconditionally inside SetupLFS, which is what caused every clone in an unprivileged host to fail apt/GitHub-release installs and log permission-denied noise.
SetupLFS's cyclomatic complexity hit 9 (max 8) after the allowInstall branch. Split the missing-binary handling into its own function.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/git/lfs.go`:
- Around line 56-57: Remove the automatic Git LFS installation path: in
pkg/git/lfs.go:56-57, log and return when binGitLFS is absent, and remove
lfsInstaller and ensureLFSBinary; in pkg/git/clone.go:110-121, remove
WithAllowLFSInstall and allowLFSInstall; in pkg/git/repo.go:176, stop
propagating the installation flag; in pkg/agent/workspace.go:480, stop enabling
LFS installation for remote agents; and in pkg/git/lfs_test.go:120-138, replace
the installation-allowed test with coverage confirming the installer is never
invoked when git-lfs is missing.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 686aea2f-7529-4b62-830f-b87ecc2e5ea2
📒 Files selected for processing (6)
pkg/agent/workspace.gopkg/agent/workspace_test.gopkg/git/clone.gopkg/git/lfs.gopkg/git/lfs_test.gopkg/git/repo.go
| if !command.Exists(binGitLFS) && !ensureLFSBinary(ctx, allowInstall) { | ||
| return |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Remove the remaining automatic Git LFS installation path.
The PR objective says missing git-lfs must fall back to pointer stubs without installation, but non-local agents still call InstallLFS through lfsInstaller.
pkg/git/lfs.go#L56-L57: log and return whengit-lfsis absent; removelfsInstallerandensureLFSBinary.pkg/git/clone.go#L110-L121: removeWithAllowLFSInstallandallowLFSInstall.pkg/git/repo.go#L176-L176: remove propagation of the installation flag.pkg/agent/workspace.go#L480-L480: stop enabling LFS installation for remote agents.pkg/git/lfs_test.go#L120-L138: replace the “installation allowed” test with coverage that the installer is never invoked when the binary is missing.
📍 Affects 5 files
pkg/git/lfs.go#L56-L57(this comment)pkg/git/clone.go#L110-L121pkg/git/repo.go#L176-L176pkg/agent/workspace.go#L480-L480pkg/git/lfs_test.go#L120-L138
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@pkg/git/lfs.go` around lines 56 - 57, Remove the automatic Git LFS
installation path: in pkg/git/lfs.go:56-57, log and return when binGitLFS is
absent, and remove lfsInstaller and ensureLFSBinary; in
pkg/git/clone.go:110-121, remove WithAllowLFSInstall and allowLFSInstall; in
pkg/git/repo.go:176, stop propagating the installation flag; in
pkg/agent/workspace.go:480, stop enabling LFS installation for remote agents;
and in pkg/git/lfs_test.go:120-138, replace the installation-allowed test with
coverage confirming the installer is never invoked when git-lfs is missing.
Summary
filter=lfsdriver isn't configured/available, it silently leaves LFS-tracked files as pointer stubs.SetupLFSdiverged from that by unconditionally trying toapt/GitHub-release installgit-lfson every clone that uses it./usr/local/bin) that install attempt always fails, wasting a network round trip and logging permission-denied errors that look like real failures even though the fallback works fine.SetupLFSnow takes anallowInstall bool. Whengit-lfsis missing:allowInstall=falsefalls back straight to pointer stubs (no install attempt, matching plain git's own default);allowInstall=trueattempts the install (via the reinstatedInstallLFS) and still falls back gracefully if that fails.pkg/agent'sgetGitOptionssetsallowInstallto!isLocalAgent(agentConfig)— the sameagentConfig.LocalcheckensureGitalready uses to decide whether to auto-install thegitbinary itself. So: a user's local machine never gets an auto-install attempt (matchesensureGitrefusing to installgitlocally too); a devsy-provisioned remote/cloud host — where devsy already has install rights — gets the same auto-install behavior forgit-lfsthat it gets forgit.--git-lfs-modestill defaults tofulland is unchanged; this only affects what happens when thegit-lfsbinary isn't found.TestSetupLFSSkipsWhenBinaryMissingAndInstallNotAllowed,TestSetupLFSInstallsWhenBinaryMissingAndInstallAllowed(both stublfsInstallerto avoid a real network call),TestIsLocalAgent.