diff --git a/src/Commands/QueryGitCommonDir.cs b/src/Commands/QueryGitCommonDir.cs
new file mode 100644
index 00000000..1076243e
--- /dev/null
+++ b/src/Commands/QueryGitCommonDir.cs
@@ -0,0 +1,26 @@
+using System.IO;
+
+namespace SourceGit.Commands
+{
+ public class QueryGitCommonDir : Command
+ {
+ public QueryGitCommonDir(string workDir)
+ {
+ WorkingDirectory = workDir;
+ Args = "rev-parse --git-common-dir";
+ RaiseError = false;
+ }
+
+ public string Result()
+ {
+ var rs = ReadToEnd().StdOut;
+ if (string.IsNullOrEmpty(rs))
+ return null;
+
+ rs = rs.Trim();
+ if (Path.IsPathRooted(rs))
+ return rs;
+ return Path.GetFullPath(Path.Combine(WorkingDirectory, rs));
+ }
+ }
+}
diff --git a/src/Models/IRepository.cs b/src/Models/IRepository.cs
index 12b1adba..90409c2f 100644
--- a/src/Models/IRepository.cs
+++ b/src/Models/IRepository.cs
@@ -4,6 +4,7 @@
{
string FullPath { get; set; }
string GitDir { get; set; }
+ string GitCommonDir { get; set; }
void RefreshBranches();
void RefreshWorktrees();
diff --git a/src/Models/Watcher.cs b/src/Models/Watcher.cs
index d0ccdea5..320f31d6 100644
--- a/src/Models/Watcher.cs
+++ b/src/Models/Watcher.cs
@@ -24,11 +24,7 @@ namespace SourceGit.Models
_wcWatcher.EnableRaisingEvents = true;
// If this repository is a worktree repository, just watch the main repository's gitdir.
- var gitDirNormalized = _repo.GitDir.Replace("\\", "/");
- var worktreeIdx = gitDirNormalized.IndexOf(".git/worktrees/", StringComparison.Ordinal);
- var repoWatchDir = _repo.GitDir;
- if (worktreeIdx > 0)
- repoWatchDir = _repo.GitDir.Substring(0, worktreeIdx + 4);
+ var repoWatchDir = _repo.GitCommonDir.Replace("\\", "/");
_repoWatcher = new FileSystemWatcher();
_repoWatcher.Path = repoWatchDir;
diff --git a/src/Resources/Locales/de_DE.axaml b/src/Resources/Locales/de_DE.axaml
index 31dc1d9b..2ebc1ae7 100644
--- a/src/Resources/Locales/de_DE.axaml
+++ b/src/Resources/Locales/de_DE.axaml
@@ -501,7 +501,7 @@
Remote löschen
Ziel:
Worktrees löschen
- Worktree Informationen in `$GIT_DIR/worktrees` löschen
+ Worktree Informationen in `$GIT_COMMON_DIR/worktrees` löschen
Pull
Remote-Branch:
Alle Branches fetchen
diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml
index b1f83836..4401e8bc 100644
--- a/src/Resources/Locales/en_US.axaml
+++ b/src/Resources/Locales/en_US.axaml
@@ -504,7 +504,7 @@
Prune Remote
Target:
Prune Worktrees
- Prune worktree information in `$GIT_DIR/worktrees`
+ Prune worktree information in `$GIT_COMMON_DIR/worktrees`
Pull
Remote Branch:
Fetch all branches
diff --git a/src/Resources/Locales/es_ES.axaml b/src/Resources/Locales/es_ES.axaml
index 6bf38df1..f57ee230 100644
--- a/src/Resources/Locales/es_ES.axaml
+++ b/src/Resources/Locales/es_ES.axaml
@@ -508,7 +508,7 @@
Podar Remoto
Destino:
Podar Worktrees
- Podar información de worktree en `$GIT_DIR/worktrees`
+ Podar información de worktree en `$GIT_COMMON_DIR/worktrees`
Pull
Rama Remota:
Fetch todas las ramas
diff --git a/src/Resources/Locales/fr_FR.axaml b/src/Resources/Locales/fr_FR.axaml
index ebb3ba89..94df8d66 100644
--- a/src/Resources/Locales/fr_FR.axaml
+++ b/src/Resources/Locales/fr_FR.axaml
@@ -476,7 +476,7 @@
Élaguer une branche distant
Cible :
Élaguer les Worktrees
- Élaguer les information de worktree dans `$GIT_DIR/worktrees`
+ Élaguer les information de worktree dans `$GIT_COMMON_DIR/worktrees`
Pull
Branche distante :
Fetch toutes les branches
diff --git a/src/Resources/Locales/it_IT.axaml b/src/Resources/Locales/it_IT.axaml
index ebfd3939..8e6f73fa 100644
--- a/src/Resources/Locales/it_IT.axaml
+++ b/src/Resources/Locales/it_IT.axaml
@@ -507,7 +507,7 @@
Potatura Remota
Destinazione:
Potatura Worktrees
- Potatura delle informazioni di worktree in `$GIT_DIR/worktrees`
+ Potatura delle informazioni di worktree in `$GIT_COMMON_DIR/worktrees`
Scarica
Branch Remoto:
Recupera tutti i branch
diff --git a/src/Resources/Locales/pt_BR.axaml b/src/Resources/Locales/pt_BR.axaml
index b4677840..c03e39d2 100644
--- a/src/Resources/Locales/pt_BR.axaml
+++ b/src/Resources/Locales/pt_BR.axaml
@@ -490,7 +490,7 @@
Prunar Remoto
Alvo:
Podar Worktrees
- Podar informações de worktree em `$GIT_DIR/worktrees`
+ Podar informações de worktree em `$GIT_COMMON_DIR/worktrees`
Puxar
Branch Remoto:
Buscar todos os branches
diff --git a/src/Resources/Locales/ru_RU.axaml b/src/Resources/Locales/ru_RU.axaml
index b2ba2158..3273ac07 100644
--- a/src/Resources/Locales/ru_RU.axaml
+++ b/src/Resources/Locales/ru_RU.axaml
@@ -508,7 +508,7 @@
Удалить внешний репозиторий
Цель:
Удалить рабочий каталог
- Информация об обрезке рабочего каталога в «$GIT_DIR/worktrees»
+ Информация об обрезке рабочего каталога в «$GIT_COMMON_DIR/worktrees»
Забрать
Ветка внешнего репозитория:
Извлечь все ветки
diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml
index 768061dd..2a8d08b5 100644
--- a/src/Resources/Locales/zh_CN.axaml
+++ b/src/Resources/Locales/zh_CN.axaml
@@ -508,7 +508,7 @@
清理远程已删除分支
目标 :
清理工作树
- 清理在`$GIT_DIR/worktrees`中的无效工作树信息
+ 清理在`$GIT_COMMON_DIR/worktrees`中的无效工作树信息
拉回(pull)
拉取分支 :
拉取远程中的所有分支变更
diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml
index 6d63c1ee..5bb68782 100644
--- a/src/Resources/Locales/zh_TW.axaml
+++ b/src/Resources/Locales/zh_TW.axaml
@@ -507,7 +507,7 @@
清理遠端已刪除分支
目標:
清理工作區
- 清理在 `$GIT_DIR/worktrees` 中的無效工作區資訊
+ 清理在 `$GIT_COMMON_DIR/worktrees` 中的無效工作區資訊
拉取 (pull)
拉取分支:
拉取遠端中的所有分支
diff --git a/src/ViewModels/Launcher.cs b/src/ViewModels/Launcher.cs
index 06479394..4307665d 100644
--- a/src/ViewModels/Launcher.cs
+++ b/src/ViewModels/Launcher.cs
@@ -282,6 +282,7 @@ namespace SourceGit.ViewModels
var isBare = new Commands.IsBareRepository(node.Id).Result();
var gitDir = node.Id;
+ var gitCommonDir = gitDir;
if (!isBare)
{
gitDir = new Commands.QueryGitDir(node.Id).Result();
@@ -291,9 +292,12 @@ namespace SourceGit.ViewModels
App.RaiseException(ctx, "Given path is not a valid git repository!");
return;
}
+ gitCommonDir = new Commands.QueryGitCommonDir(node.Id).Result();
+ if (string.IsNullOrEmpty(gitCommonDir))
+ gitCommonDir = gitDir;
}
- var repo = new Repository(isBare, node.Id, gitDir);
+ var repo = new Repository(isBare, node.Id, gitDir, gitCommonDir);
repo.Open();
if (page == null)
diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs
index 97c52d8e..5cc933e9 100644
--- a/src/ViewModels/Repository.cs
+++ b/src/ViewModels/Repository.cs
@@ -45,6 +45,12 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _gitDir, value);
}
+ public string GitCommonDir
+ {
+ get => _gitCommonDir;
+ set => SetProperty(ref _gitCommonDir, value);
+ }
+
public Models.RepositorySettings Settings
{
get => _settings;
@@ -429,11 +435,12 @@ namespace SourceGit.ViewModels
set;
} = 0;
- public Repository(bool isBare, string path, string gitDir)
+ public Repository(bool isBare, string path, string gitDir, string gitCommonDir)
{
IsBare = isBare;
FullPath = path;
GitDir = gitDir;
+ GitCommonDir = gitCommonDir;
}
public void Open()
@@ -2437,6 +2444,7 @@ namespace SourceGit.ViewModels
private string _fullpath = string.Empty;
private string _gitDir = string.Empty;
+ private string _gitCommonDir = string.Empty;
private Models.RepositorySettings _settings = null;
private Models.FilterMode _historiesFilterMode = Models.FilterMode.None;
private bool _hasAllowedSignersFile = false;