-
Notifications
You must be signed in to change notification settings - Fork 899
git lfs support #1236
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Git LFS is implemented via smudge/clean filters - it's not supported out-of-the-box but is possible to do. |
Thanks for answer. It seems that GitHub client works that way. It would be nice to have the support of the git lfs out of the box because the approach with smudge/clean filters looks very complex. |
I pushed a change today which should make it easier, but not "out of the box". |
Any progress on this? Would love to have this supported. |
It is rather trivial to support if Git+Bash are on the box. Remember that Git's filters and hooks are both assumed to be Borne Again Shell Scripts (BASH), so there's no real way around having Bash on the box. Assuming it's a Linux box, you can be assured it is there. |
What can I do to get this working? |
Just register your callback handler with Then use that callback to send the appropriate commands to Bash. |
Thanks but what git-lfs methods do I invoke on Clean, Complete, Create, etc? |
So far I'm doing stuff like this without any luck:
What commands are "appropriate" and do I still need to call the base virtual method "base.Clean(...)"? |
So I have it working on small files where "Clean" only needs to be called once. Here is the code (any ideas?)
|
More likely what you should be doing is passing the clean of filter text to |
Ok have it commiting to lfs correctly via the code below. However when I call "var blob = RepoUserControl.repo.ObjectDatabase.CreateBlob(item.FilePath);" its invoking "clean" which corrupts git-lfs as this is just used for viewing a file not commiting.
|
Here is my filter so far. It works in most cases (checkouts, merges, etc) BUT for some reason when cloning a repo some objects get there file data replaced with lfs pointers: https://github.com/zezba9000/Git-Game-GUI/blob/master/GitGameGUI/RepoUserControl.xaml.cs#L22 Why or why didn't git just expose Git-Core as a lib people could interface with... major design flaw with git. |
Was the filter invoked for those objects? If so, was |
Yes its called for all of my objects under lfs. I get no exceptions or errors that I can see. So in short maybe "mode = Clean" when it should be "mode = Smudge". Maybe this is totally off, I'm very confused as to why this is happening. One more important note! when I call "git-lfs smudge" and finish with "process.StandardInput.Close();" it doesn't trigger git-lfs to quit like it does with when I call "git-lfs clean" is called. This is being testing with GitLabs running on Ubuntu 16.04. |
Another note is this is being tested with 3 jpg images at around 300kb. |
Ok so lfs clean and smudge seem to be working. Using the bash on windows pushes just fine BUT when using libgit2sharp to push it pushes the lfs pointer and NOT the binary data. Thus corrupting the data by changing it to its text ptr on the remote server and in turn cloning will pull that corrupted lfs file. (or maybe its just smudge fails as the pointer doesn't reference any data as it didn't get pushed). Are there other hooks or something? If the bash "git push" is hooking "git-lfs push" then what do we need to do to get this working in libgit2? I think this is the last thing to get lfs working in libgit2sharp all my other tests seem to be working so far. |
Nor should it.
You need to either: a) Execute |
Ya my bad, forgot to update that comment.
Ok thanks, i'll take a look later today. |
No - LibGit2Sharp will not execute this for you. You'll likely need to run it in the context of bash (probably the bash that is included with Git for Windows):
|
@ethomson Hey so after I get "git lfs pre-push" working. I see there is also "git lfs pointer". Do you know what gitlib2sharp situation I would need to use this? I want to make sure iv'e handled all "Low level commands" listed in git-lfs to feel confident using it in my GUI at work etc. |
No - I'm afraid that I do not know what that does. @technoweenie is this a command that is needed for normal usage? |
Cool so pushing now works via this method: https://github.com/zezba9000/Git-Game-GUI/blob/master/GitGameGUI/ChangesUserControl.xaml.cs#L409 Just hope i'm not missing a condition with "git lfs pointer". |
Nah, it's more of a utility command: https://github.com/github/git-lfs/blob/master/docs/man/git-lfs-pointer.1.ronn |
Awesome tnx! |
Great! Thanks @technoweenie, and @whoisj for the info! Closing this. |
I got It seems that you have to consume the StandardOutput before waiting to exit. Like so
Thank you @zezba9000 - this made supporting lfs in my tool real easy. |
Just remind someone else who is using this way to support lfs. When you use In my case, the And you need to write the local at the first, with remote followed. See https://github.com/git-lfs/git-lfs/blob/main/docs/man/git-lfs-pre-push.adoc LibGit2Sharp Version: 0.26.2 |
Thanks for the snippet @zezba9000 It does work nicely, but it is very slow due to having to launch a new Process for every file. It only needs to launch one process (per repository) and processes all files with it. That runs much faster, especially after doing a pull where it goes over all the files with a quick clean. |
@dedmen This is much newer code base FYI: https://github.com/reignstudios/Git-It-GUI |
Hi @dedmen, thank you so much, this was exactly what I was looking for, I managed to integrate (maybe as of now, still a bit hackish) your Gist in git-tfs, which unfortunately lacks git-LFS (or I think, any kind of filtering) awareness. I tried it out after setting up a TFS repository containing also binaries which in the git repo cloned from it, are tracked by LFS (via the .gitattributes) and your LFSFilter is nicely running "Clean" on tracked binaries, before libgit2sahrp which is used by git-tfs creates a git commit. Unfortunately, it's another story with binaries commited in git which git-tfs should then send to TFS. Running the command which will do that would checkout the commit to be transferred to TFS into a temporary "TFS workspace", which is just a folder containing the changes from the commit, but not a diff, but as their actual content, to let TFS know about it and do its own "diff magic" if applicable. Here I would have expected the LFSFilter to "smudge", but it actually "cleaned", therefore git LFS pointer files have been checked in to TFS, instead of the actual blobs. |
I'm running my code in a git-SVN sync tool. The filter code, just does what it gets told to do by libgit2. So there shouldn't be an issue in the filter itself. But maybe the post checkout is needed. |
I guess you're right, I traced all method calls of your filter and only Initialize, Create, Clean and Complete are being called in general, when I fetch / pull data from TFS, also it's the only occasion I've seen Smudge being called, I would have expected to see it when checking in to TFS (so in the other direction). None of PrePush/PostCheckout/PostCommit have been called, I too suspected that could be the issue, you seem to confirm by emphasizing PostCheckout needs to be called... |
I figured it out how to make it work when checking in to TFS as well, it was just changing one line in the git-tfs code. I will fork git-tfs and publish my changes, which I would eventually PR upstream, if it's ok with you to also incorporate your Gist, @dedmen ? |
I didn't realize I forgot to put a license onto it. |
Does libgit2sharp support working with repo that contains github lfs binding. If so, where i can find any info how to use it?
The text was updated successfully, but these errors were encountered: