denolehov / obsidian-git

Backup your Obsidian.md vault with git
MIT License
6.13k stars 251 forks source link

Large File Storage #14

Open zharinov opened 3 years ago

zharinov commented 3 years ago

@denolehov, thank you for this plugin!

I tried to use git-lfs feature for my images sub-folder and here is error in my console:

This repository is configured for Git LFS but 'git-lfs' was not found on your path.
If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/pre-push.

Basically, hook content looks like this:

#!/bin/sh
command -v git-lfs && git lfs pre-push "$@"

I wonder if this can be fixed just by passing parent PATH via this option.

More context: Obsidian: 0.9.14 OS: macOS Big Sur

To reproduce, I guess it would be enough to follow this setup. Also, maybe I'll be able to figure out obsidian plugin development setup and debug it on my own.

UPD. As I can see, obsidian process doesn't contain /usr/local/bin directory in its PATH, i.e. it uses system-wide git command instead of homebrew-installed one.

denolehov commented 3 years ago

Hey, I will look into this closer to next weekend. Sorry for the late reply.

danmichaelo commented 3 years ago

Similar issue to #21, but in the case of git-lfs, I don't think there is a git-config option to set the path to git-lfs. So perhaps the best would be to introduce two new plugin settings: "Path to git" and "Path to git-lfs", that can be used to override the system defaults? Never mind, you can tell simpleGit to use a specific git binary, but it will still use the git-lfs binary on PATH, so I'm not really sure what would be a good way to make this configurable. Modifying the PATH variable would of course work, but it seems a bit outside the scope of this plugin to do.

sascha-wolf commented 3 years ago

I've encountered the same issue.

My solution was to manually update the .git/hooks installed by git-lfs (post-commit, post-checkout, post-merge, and pre-push) and add the following line at the top of each one:

PATH="$PATH:/usr/local/bin"

(This assumes that the git-lfs binary resides in /usr/local/bin, which is the case if you installed it through brew by example.)

This will update the PATH variable for the scope of the script and not impact your "usual" PATH, and as such can be considered safe.

frankreporting commented 3 years ago

Tried the above recommendation but still got errors.

Cannot add files: git-lfs
filter-process: git-lfs: command not found
fatal: the remote end hung up unexpectedly

I checked git-lfs location with which and it was usr/local/bin, added that path line in the top of each hook.. though was I supposed to update them some other way first, or is that what sascha-wolf meant by manually updating? Any other ideas what could be causing it to fail?

cor commented 2 years ago

This is still an issue as of 2021-09-01

mracette commented 2 years ago

I had the same issue as @frankreporting when I installed git-lfs using homebrew (location was /opt/homebrew/bin).

To resolve it, I installed the package at https://git-lfs.github.com/ and ran install.sh, which installed git-lfs to /usr/local/bin (you may also be able to just move the binary).

After that, I was able to add PATH=$PATH:/usr/local/bin to the git hooks and after restarting Obsidian everything worked.

bevsxyz commented 2 years ago

I've encountered the same issue.

My solution was to manually update the .git/hooks installed by git-lfs (post-commit, post-checkout, post-merge, and pre-push) and add the following line at the top of each one:

PATH="$PATH:/usr/local/bin"

(This assumes that the git-lfs binary resides in /usr/local/bin, which is the case if you installed it through brew by example.)

This will update the PATH variable for the scope of the script and not impact your "usual" PATH, and as such can be considered safe.

@sascha-wolf Why should I do that? My git-lfs binary is already in the path.

sascha-wolf commented 2 years ago

@sascha-wolf Why should I do that? My git-lfs binary is already in the path.

If it works for you, you don't. It didn't for me, git-lfs wasn't in the PATH of the script execution.

christyray commented 2 years ago

Like @frankreporting and @mracette, I was having the same issue where it still wasn't working even after I added PATH="$PATH:/usr/local/bin" to the top of each git hook.

I didn't want to download and install git-lfs manually since I wanted to maintain the management by Homebrew. I was specifically getting an error message about filter-process, and I realized that was part of the filters Git LFS defines in the .gitconfig.

I updated my global .gitconfig to refer to /usr/bin/local/git-lfs instead of just git-lfs on all of the filter lines. That combined with adding PATH="$PATH:/usr/local/bin" to the top of each git hook fixed it for me!

That section of my global .gitconfig now looks like:

[filter "lfs"]
    process = /usr/local/bin/git-lfs filter-process
    required = true
    clean = /usr/local/bin/git-lfs clean -- %f
    smudge = /usr/local/bin/git-lfs smudge -- %f
finn-matti commented 2 years ago

Thanks @christyray, your tip solved it for me!

You can put that section also inside the .git/config file of the Obsidian repo itself, if you don't want to change your global .gitconfig file.

AlekseiCherkes commented 1 year ago

If you don't want to modify gitconfig or git hooks you can create git.sh file in the root dir of your vault or anywhere else you want then specify it as a git command in "Obsidian Git" settings.

#!/bin/bash

# Implementation of git command with Homebrew binaries added to the PATH.
# Needed to make Obsidian Git plugin work with git-lfs. To use this file specify 
# the global global path to this file in "Custom Git binary path" setting of "Obsidian Git".

export PATH=$PATH:/usr/local/bin
/usr/local/bin/git "$@"

Works well for me!

dwSun commented 1 year ago

Like @frankreporting and @mracette, I was having the same issue where it still wasn't working even after I added PATH="$PATH:/usr/local/bin" to the top of each git hook.

I didn't want to download and install git-lfs manually since I wanted to maintain the management by Homebrew. I was specifically getting an error message about filter-process, and I realized that was part of the filters Git LFS defines in the .gitconfig.

I updated my global .gitconfig to refer to /usr/bin/local/git-lfs instead of just git-lfs on all of the filter lines. That combined with adding PATH="$PATH:/usr/local/bin" to the top of each git hook fixed it for me!

That section of my global .gitconfig now looks like:

[filter "lfs"]
  process = /usr/local/bin/git-lfs filter-process
  required = true
  clean = /usr/local/bin/git-lfs clean -- %f
  smudge = /usr/local/bin/git-lfs smudge -- %f

works for me

Vinzent03 commented 1 year ago

I've added a setting to add paths to the PATH env var. Can one of you try the new setting?

christyray commented 1 year ago

I've added a setting to add paths to the PATH env var. Can one of you try the new setting?

@Vinzent03 - The new setting doesn't appear to be updating my path, at least based on the output of process.env.PATH in the console. But, Obsidian now (and possibly for a while - I haven't checked this recently) seems to be using the PATH variable I have set in .zshrc, and that fixed the issues I was having with Git LFS being located.

TYZRPVX commented 1 year ago

Same problem, add lfs config to .gitconfig and create git.sh file cannot work

AlekseiCherkes commented 1 year ago

@Vinzent03 Seems to work for me. Little notch: the path should be specified with the trailing /. Obsidian Git treats it as a path to file (not directory) otherwise.

Vinzent03 commented 1 year ago

@AlekseiCherkes You mean the settings description should be improved?

TYZRPVX commented 1 year ago

I've added a setting to add paths to the PATH env var. Can one of you try the new setting?

work for me.

Obsidian Git - Advanced - Additional PATH environment variable paths - append /usr/local/bin

AlekseiCherkes commented 1 year ago

@AlekseiCherkes You mean the settings description should be improved?

@Vinzent03 I don't know what's happend exactly, but everything is OK on my side now. I wasn't able to reproduce the issue.

fxsalazar commented 1 year ago

I've added a setting to add paths to the PATH env var. Can one of you try the new setting?

In my case, I had to add /opt/homebrew/bin/ and it worked.

icefed commented 7 months ago

News:

Add /opt/homebrew/bin or your git-lfs path in obsidian-git setting Additional PATH environment variable paths can solve this.

obsidian-git don't use my zsh $PATH.

frankreporting commented 4 months ago

I've added a setting to add paths to the PATH env var. Can one of you try the new setting?

In my case, I had to add /opt/homebrew/bin/ and it worked.

This also worked for me. Thank you!

JV-conseil commented 3 months ago

Adding

/opt/homebrew/bin

in

Obsidian Git > Advanced > Additional PATH environment variable paths

worked for me 👌

Adding `/opt/homebrew/bin` in Obsidian Git > Advanced > Additional PATH environment variable paths

Git LFS commit and push now work on Obsidian with git-lfs installed with Homebrew ✅

rlkennedyreid commented 3 months ago

Adding

/opt/homebrew/bin

in

Obsidian Git > Advanced > Additional PATH environment variable paths

worked for me 👌

Adding /opt/homebrew/bin in Obsidian Git > Advanced > Additional PATH environment variable paths

Git LFS commit and push now work on Obsidian with git-lfs installed with Homebrew ✅

This also worked for me