0

The main aim of what I'm trying to is to have two Git repositories in the same tree and for TortoiseGit to display differences of a modified file.

Here is the scenario. Two git repos: MainProj and SubProj and cloned as shown below:

MainProj                          SubProj
.git\                              .git\
file0.txt                          file_s1.txt
dir1\                              file_s2.txt
  file1.txt
dir2\
  file2.txt

I want to continue having the SubProj repository (.git) in its current place, but having its work files in the MainProj work tree, under dir1. So the MainProj tree contains its own work files as well as those from SubProj with the latter continue having its repository in SubProj.

The disk will be as follows:

MainProj                         SubProj
.git\                             .git\
file0.txt                         (files moved to MainProj/dir1)
dir1\
  file1.txt
  file_s1.txt (moved from SubProj)
  file_s2.txt (moved from SubProj)
dir2\
  file2.txt

To indicate this configuration to git, in a cmd shell.

    >set "GIR_DIR=C:\path\to\SubProj"
    >set "GIR_WORK_TREE=C:\path\to\MainProj\dir1"

Continuing in the same shell, I modify file_s1.txt

    >echo xxx yyy zzz >> "C:\path\to\MainProj\dir1\file_s1.txt"

Continuing in the same shell, cd:

    >cd C:\path\to\SubProj

In this directory, I run:

    "D:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe" /command:commit 

TortoiseGit correctly displays that file_s1.txt has been modified.

enter image description here

So far, so good.

However, double clicking on the modified file: I get:

enter image description here

How can this be overcome?

BTW When I tell it where to find the file, i.e. in C:\path\to\MainProj\dir1 TGit shows the differences correctly.

Further notes:

Using forward slashes for setting GIR_DIR and GIR_WORK_TREE the problem persists

Adding the parameter /path:C:/path/to/MainProj/dir1 the problem persists

Lastly, in directories:

    >git status 

works fine. TortoiseGit 2.11.0.0, git version 2.40.0.windows.1

Alex Net
  • 164
  • 12
  • 1
    _"have two Git repositories in the same tree"_ - what do you mean by "same tree"? – Dai Apr 20 '23 at 23:44
  • The work files of one repository (as above ```SubProj```) are kept in the work tree of another (as above ```MainProj```) and where its .git resides. However the .git directory of first is in a different directory. – Alex Net Apr 21 '23 at 08:49
  • ...that sounds like a bad idea and I have no idea how that could even work in practice. `git` _expects_ to fully control/own each worktree in your filesystem - what underlying problem are you facing and why do you think this will help? – Dai Apr 21 '23 at 08:53
  • Leaving aside whether it is a bad idea or not... Git provides this facility and works fine, as explained above. The issue is with TortoiseGit. – Alex Net Apr 21 '23 at 08:56

1 Answers1

1

TortoiseGit ignores setting GIT_WORK_TREE environment variable, but it also ignores git config core.worktree setting.

However the solution is simple - in MainProj/dir1 create file .git that contains gitdir: <path>, where <path> points to SubProj/.git folder (see more in this answer). This solution works transparently with TortoiseGit.

user14967413
  • 1,264
  • 1
  • 6
  • 12
  • Indeed it does work with TortoiseGit. Thanks very much for this. You can only use TortoiseGit within MainProj but not in SubProj even if you add to it the core.worktree setting. This is an observation for a bit of a contrived situation: it is not possible to have in MainProj the .git directory and the .git file (at the same time). – Alex Net Apr 25 '23 at 16:47
  • It looks like that a better solution is to use hardlinks in the MainProj to the SubProj files. – Alex Net Apr 25 '23 at 16:59