exa icon indicating copy to clipboard operation
exa copied to clipboard

FR: Respect environment variables GIT_DIR and GIT_WORK_TREE

Open jonathf opened this issue 4 years ago • 8 comments

Thanks for creating such an awesome upgrade to the ls command!

I use git-bare to manage my dotfiles: https://www.atlassian.com/git/tutorials/dotfiles TL;DR we change git-dir and git-work-tree so $HOME acts as repo root in a more elegant way.

I'd like to get exa working with this setup for its --git flag (using a function wrapper). Would it be possible to let exa read GIT_DIR and GIT_WORK_TREE and pass them to git when they exists and where appropriate?

jonathf avatar Aug 24 '20 16:08 jonathf

Why the FR in the title?

It seems possible to respect GIT_DIR since it’s mentioned in git2-rs documentation: https://docs.rs/git2/0.13.15/git2/struct.Repository.html#method.open_from_env

And it’s totally possible to have GIT_WORK_TREE points to a git repository that exa could use.

ariasuni avatar Jan 03 '21 21:01 ariasuni

Because I consider this a "feature request". But I can remove it if it is a bad fit for the issue or if I a misunderstood what FR means here.

Yes I imagined it would be possible. However I am not a rust-dev, so I have no idea how complicated sych a feature will be.

jonathf avatar Jan 04 '21 13:01 jonathf

+1 on this, with the same usecase.

Will try to raise a PR if I get time

iamkroot avatar Oct 30 '22 07:10 iamkroot

#1141 solves this.

Note that I'm seeing very long delays to output (almost 3-4 seconds) when GIT_DIR points to my dotfiles repo. This is probably a libgit slowness issue because that repo is quite large, and the delays disappear on a small repo.

iamkroot avatar Oct 30 '22 08:10 iamkroot

Awesome! This would be great to have merged.

@iamkroot, Will this also respect GIT_WORK_TREE?

jonathf avatar Oct 30 '22 12:10 jonathf

@iamkroot, Will this also respect GIT_WORK_TREE?

Probably not. libgit does not seem to support this according to the flag documentation.

  • In the future, this flag will also cause git_repository_open_ext * to respect $GIT_WORK_TREE and $GIT_COMMON_DIR; currently, * git_repository_open_ext with this flag will error out if either * $GIT_WORK_TREE or $GIT_COMMON_DIR is set.

iamkroot avatar Oct 30 '22 16:10 iamkroot

Okay thanks. I should be able to make something work with that.

jonathf avatar Oct 31 '22 07:10 jonathf

So with https://github.com/ogham/exa/pull/1141 you can use something like direnv and a .envrc file like...

export GIT_DIR=$HOME/.cfg
export GIT_WORK_TREE=$HOME

...and the exa's git column will work in bare repositories?

eggbean avatar Oct 31 '22 19:10 eggbean