-
Notifications
You must be signed in to change notification settings - Fork 970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Git LFS support to uv-git
crate
#10335
Conversation
- Added a `git lfs fetch` step after fetching the repository but before cloning it locally. - Git LFS step is ignored if `git-lfs` is not installed. - Errors while executing Git LFS are reported as normal.
crates/uv-git/src/git.rs
Outdated
/// We search for the Git LFS binary instead of using `git lfs` so that we can | ||
/// distinguish Git LFS not being installed (which we can ignore) from | ||
/// LFS errors (which should be returned). | ||
static GIT_LFS: LazyLock<Option<PathBuf>> = LazyLock::new(|| which::which("git-lfs").ok()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not certain this detection method is portable to all end user systems. For example, I can have git lfs installed and working but I not have git-lfs binary on the path. I think probing git lfs
directly is likely the most portable approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I've updated the logic so now instead of searching for git-lfs
on the path, it just tries to run git lfs version
the first time LFS is invoked and uses the success of that command as an indicator of LFS availability.
I'd definitely be interested in if anyone has a cleaner way of determining whether LFS is available. I was initially going to just check if the LFS fetch command returned 127
(command not found), but that return code isn't available in Powershell, so that approach isn't portable across shells.
Now instead of checking for a `git-lfs` binary on the path, we just try to run `git lfs version` to verify LFS is available.
Agree, since this is technically a possible breaking change a way to Thoughts @zanieb? |
- Added `UV_GIT_LFS` environment variable - Moved LFS fetch step so it is now gated behind `UV_GIT_LFS` flag.
@samypr100 I've updated the PR so that the LFS fetch step is off by default, and is enabled by setting the environment variable |
Opt-in is a great idea — it makes us much more likely to accept the feature. |
Did you do any benchmarking of this? |
Testing on my local system with a repository with a small number of tracked files ( That said, the added overhead should be equal to the time required to run |
|
Summary
Closes #3312.
This PR adds Git LFS support to the
uv-git
crate by using thegit-lfs
CLI to fetch required LFS objects for a revision following the call togit fetch
.The LFS fetch step is disabled by default and only enabled if the environment variable
UV_GIT_LFS
is set.When enabled, the LFS fetch step is run for all repositories regardless of whether they have associated LFS objects. The step is skipped if the
git-lfs
CLI tool isn't installed.Test Plan
I verified that the minimal example in the linked issue passes, i.e. this command now succeeds:
I also verified that non-LFS repositories still work, with or without
git-lfs
installed.To Replicate
Attempt to use uv to install a Git dependency that contains LFS objects (e.g.
uv pip install git+https://github.com/grebnetiew/lfs-py.git
). This should fail with a smudge filter error.Re-run the same command with the added environment variable
UV_GIT_LFS=1
. The install should now succeed.Potential Changes / Improvements
With this change LFS objects in a given revision will always be downloaded if the user has Git LFS installed, which may not always be desired behavior. It might be helpful to add a field to theuv
settings and/or an environment variable so that the LFS step can be disabled if needed.Enabling/disabled via environment variable has now been implemented.