Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git: Support for gitdir #77215

Open
deitry opened this issue Jul 11, 2019 · 12 comments
Open

Git: Support for gitdir #77215

deitry opened this issue Jul 11, 2019 · 12 comments
Assignees
Labels
feature-request Request for new features or functionality git GIT issues help wanted Issues identified as good community contribution opportunities
Milestone

Comments

@deitry
Copy link

deitry commented Jul 11, 2019

I use two git repositories within project folder - one is .git and second is .git_dev. First is for project and second is to track my local config files. I used to work with second via alias git dev which stands for git --git-dir=.git_dev, but for now I explore ways to list changes within both repos in git sideview.

What I did:

  1. I create folder aside the main project folder(consider it project) and call it project_dev
  2. Initialize new repo in new folder with git init --separate-git-dir ../project/.git_dev. It creates file project_dev/.git with related line.
  3. Then create new file within project_dev folder and open it in Code. Now I'm able to view changes for both repos, but one called project_dev tracks the project_dev folder, not the project
  4. So my next step is to add setting worktree=/path/to/project in .git_dev/cofig. Now git sideview perfectly represents current changes for project_dev aside to main project.

And here I run into two issues:

  1. if I try to click on changed file in project_dev section of sideview, an error occurs with message: Unable to open 'filename (Working Tree)': Unable to read file (Error: File not found (/path/to/project_dev/filename)). like it doen't respect setting worktree at all.
  2. If I reload Code, even if I open file from project_dev folder, second repo is not shown. If I remove worktree setting, project_dev repo is shown again and I have to add worktree setting again to get changes properly.

Example repo:
https://github.com/deitry/vscode-two-git-repos-issues


So, on the one hand I consider current behaviour as buggy. On the other hand, I make a request to add option to pass as many --git-dirs as I want by making it a list:

"git.gitdirs: [ ".git", ".git_dev"]
@vscodebot vscodebot bot added the git GIT issues label Jul 11, 2019
@deitry
Copy link
Author

deitry commented Jul 11, 2019

Oh, and I can't see any gutters for files tracked in project_dev, but ignored in project, so this is another issue to put in the box.

@joaomoreno
Copy link
Member

Worktree support: #68038

@joaomoreno joaomoreno changed the title Support for gitdir and worktree options Support for gitdir Jul 18, 2019
@joaomoreno joaomoreno changed the title Support for gitdir Git: Support for gitdir Jul 18, 2019
@joaomoreno joaomoreno added feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities labels Jul 18, 2019
@joaomoreno joaomoreno added this to the Backlog milestone Jul 18, 2019
@joaomoreno joaomoreno removed their assignment Jul 18, 2019
@joaomoreno joaomoreno self-assigned this Oct 9, 2019
@texastoland
Copy link

texastoland commented Apr 18, 2020

Workaround for anyone else arriving from #80946:

alias dotfiles='GIT_DIR=$DOTFILES_REPO GIT_WORK_TREE=~'
dotfiles git status
dotfiles code ~

@joaomoreno joaomoreno removed their assignment Nov 11, 2020
tankris pushed a commit to tankris/dotfiles that referenced this issue Nov 25, 2020
   - The alias has been changed in order to support opening the git bare
   repo from vs code
   - Source: microsoft/vscode#77215 (comment)
tankris added a commit to tankris/dotfiles that referenced this issue Nov 30, 2020
   - The alias has been changed in order to support opening the git bare
   repo from vs code
   - Source: microsoft/vscode#77215 (comment)
@lszomoru lszomoru self-assigned this Oct 4, 2021
@lamusique
Copy link

@lszomoru Look forward to your fix! 🤞🏻

@RyzeNGrind
Copy link

Workaround for anyone else arriving from #80946:

alias dotfiles="GIT_WORK_TREE=~ GIT_DIR=$DOTFILES_DIR"
dotfiles git status
dotfiles code ~

Does anybody know how to make this work for $SHELL=usr/bin/fish? @faho

Previously I had

alias -s dotfiles='/usr/bin/git --git-dir=$WORKSPACES/ClusterLab/dotfiles/ --work-tree=$HOME'

But I tried to modify it without specifying an application and it didn't work.

@ColCh
Copy link
Contributor

ColCh commented Feb 14, 2023

Does anybody know how to make this work for $SHELL=usr/bin/fish? @faho

@RyzeNGrind

https://fishshell.com/docs/2.2/faq.html#faq-single-env

alias -s dotfiles='env GIT_WORK_TREE="$HOME" GIT_DIR="$WORKSPACES/ClusterLab/dotfiles/" git

garrofederico added a commit to garrofederico/.dotfiles that referenced this issue Jul 14, 2023
vscode

- The alias has been changed in order to support opening the git bare
repo from vs code
- Source: microsoft/vscode#77215 (comment)
@mattmc3
Copy link

mattmc3 commented Aug 28, 2023

Does anybody know how to make this work for $SHELL=usr/bin/fish? @faho

@RyzeNGrind - This is how you'd do the same in Fish:

function dotfiles --description "dotfiles commands with bare git repo"
    GIT_WORK_TREE=~ GIT_DIR=~/.dotfiles $argv
end

Then run dotfiles code ~.

@sparr
Copy link

sparr commented Dec 1, 2023

What is the expected behavior when specifying two different gitdirs?

I arrived here looking for similar functionality, to specify a single non-standard git.gitdir in the vscode configuration.

Launching vscode from the command line with a different environment variable is not an effective solution when I need to have multiple projects open with different settings.

@mattmc3
Copy link

mattmc3 commented Dec 1, 2023

@sparr I you look at code --help you will find the --new-window or -n option. You can use that to open multiple instances of vscode from the terminal.

$ # regular dotfiles
$ GIT_WORK_TREE=~ GIT_DIR=~/.dotfiles code --new-window
$ # private dotfiles
$ GIT_WORK_TREE=~ GIT_DIR=~/.dotfiles.local code --new-window

Each running instance of VS Code will then have its own $GIT_DIR set.

Screenshot 2023-12-01 at 12 57 36 PM

If you find that VS Code is reusing a running instance, you may also find it helpful to check your new window settings.

Screenshot 2023-12-01 at 12 59 28 PM

@texastoland
Copy link

Ping @lszomoru if you have any insight about planning etc. 🛎️

@sparr
Copy link

sparr commented Dec 29, 2023

Another problem with the $GIT_DIR approach is that it breaks workflows that interact with other git repositories. I need vscode's extensions and behavior to honor the gitdir associated with my workspace, but the terminal to behave normally so I can perform git operations in other repositories (such as submodules). I might be able to accomplish this by unsetting $GIT_DIR in each terminal I open, but that seems hack-y.

@texastoland
Copy link

@sparr Check out terminal profiles. You can either unset the variable or disable inheritance altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality git GIT issues help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

No branches or pull requests

9 participants