sublime_merge icon indicating copy to clipboard operation
sublime_merge copied to clipboard

Specify git dir and work tree via environment variable

Open adithyabsk opened this issue 4 years ago • 11 comments

Version info

  • OS: macOS 10.15.7
  • Build: 2032

Description Launching sublime merge with GIT_DIR=$HOME/.dotfiles.git/ GIT_WORK_TREE=$HOME does not seem to work (see screenshot below). I see in the dev log that work tree support was added and I assume that would require configuration in the .git folder. I am avoiding that approach here so that my entire $HOME directory doesn't get recognized at a git repo.

Was curious if there is a way to get sublime merge to acknowledge the specified env vars

Steps to reproduce

  • Setup a simple bare repo and try to open sublime merge with the above environment variables specified.
GIT_DIR=$HOME/.dotfiles.git/ GIT_WORK_TREE=$HOME smerge .

Screenshot image

adithyabsk avatar Oct 23 '20 22:10 adithyabsk

Hi @adithyabsk,

Thank you for the report.

I'm not sure that a bare repo with a work tree is a valid git configuration. From the git documentation: GIT_WORK_TREE is the location of the root of the working directory for a non-bare repository.

Could you confirm whether you mean empty repo instead of bare repo in the steps to reproduce?

Additionally, I'd just like to confirm that .dotfiles.git is the name of the single directory containing your Git repository data.

Thanks, - Dylan

dpjohnst avatar Oct 26 '20 00:10 dpjohnst

Hi @dpjohnst my understanding of that statement is that the moment GIT_WORK_TREE is specified the "repo" becomes non-bare since it has a working tree.

Maybe I was not super clear in my above bug report. What I mean to say is that I initially set up my project as a bare repo so that the contents of the git revision information would be stored in a particular folder of my choosing. (in this case .dotfiles.git rather than a .git hidden folder.

This is the repo in question and my setup instructions are listed in the README: https://github.com/adithyabsk/dotfiles

adithyabsk avatar Oct 30 '20 00:10 adithyabsk

Hi @adithyabsk,

Thank you for the further clarification - I misunderstood what you were trying to achieve here.

At the moment we don't support the GIT_WORK_TREE env var; however, I'm in the process of adding support for it now. I'll send you a further update here once it's been added in a new build.

Thanks, - Dylan

dpjohnst avatar Nov 03 '20 06:11 dpjohnst

Just chiming in to add I would also like to see this being implemented.

avesst avatar Feb 09 '21 17:02 avesst

Same issue and use case as the OP. When I need do work on this repo I simlink my git dir git_dotfiles to .git to work with sublime merge

andreagrax avatar May 09 '21 12:05 andreagrax

@dpjohnst Thought I'd follow up on this issue to see where it stood on the priority list

adithyabsk avatar Aug 29 '21 03:08 adithyabsk

The work dir can also be set in .git/config, the option is called worktree, please also support that so I don't have to use the env var if my repo is set up correctly already.

capr avatar Nov 26 '21 17:11 capr

My exact use case and issue... Subscribing thread.

chief-wrench avatar Feb 15 '22 11:02 chief-wrench

@andreagrax you wrote

Same issue and use case as the OP. When I need do work on this repo I simlink my git dir git_dotfiles to .git to work with sublime merge

I tried the same, and opened $HOME in smerge. Result: smerge lists all my files below $HOME as "untracked", I guess because it ignores "showUntrackedFiles = no" in my ~/.git/config

chief-wrench avatar Feb 15 '22 11:02 chief-wrench

I made it work!

I also use a bare repo to track my dotfiles, and I am able to open it in Sublime Merge. It uses the core.worktree configuration property, which was apparently not working with Sublime in the past.

Basically the only thing to change is to replace bare = true by worktree = /home/<your-name> in the config file (so the repo is effectively not bare anymore):

[core]
	repositoryformatversion = 0
	filemode = true
	worktree = /home/<your-name>
[status]
	showUntrackedFiles = no

But, at the moment Sublime ignores the property status.showUntrackedFiles and will show all the untracked files of your home folder (see https://github.com/sublimehq/sublime_merge/issues/1544). To prevent this, you can create a .gitignore containing just /* in your home directory. HOWEVER, this .gitignore has a side effect on git checkout. Indeed, usually when you clone the repository on a new machine and run git checkout, if some files in your home folder are different than the ones in your repository, git displays the message error: The following untracked working tree files would be overwritten by checkout:. But with this .gitignore in your home directory, git checkout will simply override the files that are in you home directory by the ones from your repository. Without warning! You don't need git checkout anymore though, now that we can open the repo in Sublime Merge, we just keep the files we want, and we discard the others ;-)

~There is another thing that doesn't work: if you sign your commits, then your signature will be shown as invalid:~ → That's fixed in build 2077!

image

~I haven't created an issue for this one though, as this is an edge case and they already have more than 800 open issues on GitHub...~ EDIT: there are way more issues, see here. Nothing preventing me from using the repo though, I just have to type a few command lines sometimes.


Here are all the steps to create a repo to track your dotfiles in your home directory:

git init --bare ~/my-config
cd ~/my-config
git config --unset core.bare
git config core.worktree /home/<your-name>
git config status.showUntrackedFiles no
echo "/*" > ~/.gitignore

And you can now open the folder ~/my-config with Sublime Merge!

To add files to your repo, use git add -f ~/path/to/your/.file.


And remember, don't use git checkout and, WARNING: be very careful with other git commands! Commands like git clean could delete every untracked files from your home directory! This means everything except your dotfiles.


Zwyx avatar Jul 15 '22 13:07 Zwyx

Hi, any progress on this?

istudyatuni avatar Jul 01 '24 23:07 istudyatuni