Lazygit: Provide an option to pass `--work-tree` to git

Created on 3 Apr 2020  路  12Comments  路  Source: jesseduffield/lazygit

Is your feature request related to a problem? Please describe.
I have a repo that I use to store my dotfiles, which is essentially a bare repo that I can use from anywhere just passing some arguments: git --git-dir=$HOME/dotfiles/ --work-tree=$HOME. --git-dir in this case is pointing to the bare repo (in this case, I think I could use the flag --path provided by lazygit), and --work-tree is pointing to my home folder, which is the root where I store the dotfiles (for more info, it is basically what is described in https://www.atlassian.com/git/tutorials/dotfiles).

So, TL;DR; Apparently, lazygit provides no way of configuring the --work-tree, so I can't use it on this repo.

Describe the solution you'd like
It would be nice to have either a specific config for this, like --work-tree=$HOME (same as was done on https://github.com/jesseduffield/lazygit/pull/414 with --git-dir), which would default to the git dir if you don't pass.
Another solution would be to have a config with a list of arguments to pass to git anytime lazygit calls it, like --git-args="--work-tree=$HOME", and then lazygit would execute git --work-tree=$HOME", instead of just git, which would make lazygit a lot more flexible.

Describe alternatives you've considered
None that I can think of, other than using just git directly

Additional context
N/A

What do you think?

enhancement

Most helpful comment

@GabrielDuarteM @80KiloMett @micmarty @sebastiangelotte @vbauerster could you give this PR a test? Should work fine when invoked like so:

lazygit --git-dir=$HOME/.cfg --work-tree=$HOME

All 12 comments

The --git-args flag sounds like a decent idea, this way we can avoid having a bunch of flags while still allowing users to use git's flags

pinging @dawidd6 @jesseduffield @mjarkk for their input

I'm all in for --work-tree option, as I use this dotfiles management approach too, but what other options one would like to pass to every executed git command?

Perhaps --exec-path or --namespace, but I think for now just adding --work-tree would be good enough

I'm cool with a --work-tree option

I've done some more digging and we're going to support the --git-dir and --work-tree args. I want to hold off on a generic --git-args option until we really need it: this particular issue requires some bespoke code and I get the feeling that may also be the case with other git args so supporting any random git args could mislead users.

At any rate I'm working on this feature now: https://github.com/jesseduffield/lazygit/pull/1023

@GabrielDuarteM @80KiloMett @micmarty @sebastiangelotte @vbauerster could you give this PR a test? Should work fine when invoked like so:

lazygit --git-dir=$HOME/.cfg --work-tree=$HOME

Is there a way for lazygit to accept or read the local --git-dir settings, for example: showUntrackedFiles = no?

@kguidonimartins that PR specifically checks the showUntrackedFiles arg so that should be fine. As for other settings, it might need to work on a case by case basis as often it's not as simple as just passing the arg through to git

Just tested #1023, looks like it's ok, haven't spot any issue.

thanks @vbauerster , I'll close this issue for now and if you come across any issues feel free to comment them here

Deleted comment and opened #1063.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cbeley picture cbeley  路  6Comments

rubensr-pc picture rubensr-pc  路  5Comments

kristijanhusak picture kristijanhusak  路  6Comments

pshirshov picture pshirshov  路  3Comments

jclappiway picture jclappiway  路  7Comments