Skip to content

Commit cea8a90

Browse files
authored
refactor: use $GIT_COMMON_DIR instead of cut $GIT_DIR/worktrees (#1103)
1 parent 265aaa1 commit cea8a90

File tree

14 files changed

+51
-16
lines changed

14 files changed

+51
-16
lines changed

src/Commands/QueryGitCommonDir.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.IO;
2+
3+
namespace SourceGit.Commands
4+
{
5+
public class QueryGitCommonDir : Command
6+
{
7+
public QueryGitCommonDir(string workDir)
8+
{
9+
WorkingDirectory = workDir;
10+
Args = "rev-parse --git-common-dir";
11+
RaiseError = false;
12+
}
13+
14+
public string Result()
15+
{
16+
var rs = ReadToEnd().StdOut;
17+
if (string.IsNullOrEmpty(rs))
18+
return null;
19+
20+
rs = rs.Trim();
21+
if (Path.IsPathRooted(rs))
22+
return rs;
23+
return Path.GetFullPath(Path.Combine(WorkingDirectory, rs));
24+
}
25+
}
26+
}

src/Models/IRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public interface IRepository
44
{
55
string FullPath { get; set; }
66
string GitDir { get; set; }
7+
string GitCommonDir { get; set; }
78

89
void RefreshBranches();
910
void RefreshWorktrees();

src/Models/Watcher.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ public Watcher(IRepository repo)
2424
_wcWatcher.EnableRaisingEvents = true;
2525

2626
// If this repository is a worktree repository, just watch the main repository's gitdir.
27-
var gitDirNormalized = _repo.GitDir.Replace("\\", "/");
28-
var worktreeIdx = gitDirNormalized.IndexOf(".git/worktrees/", StringComparison.Ordinal);
29-
var repoWatchDir = _repo.GitDir;
30-
if (worktreeIdx > 0)
31-
repoWatchDir = _repo.GitDir.Substring(0, worktreeIdx + 4);
27+
var repoWatchDir = _repo.GitCommonDir.Replace("\\", "/");
3228

3329
_repoWatcher = new FileSystemWatcher();
3430
_repoWatcher.Path = repoWatchDir;

src/Resources/Locales/de_DE.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@
501501
<x:String x:Key="Text.PruneRemote" xml:space="preserve">Remote löschen</x:String>
502502
<x:String x:Key="Text.PruneRemote.Target" xml:space="preserve">Ziel:</x:String>
503503
<x:String x:Key="Text.PruneWorktrees" xml:space="preserve">Worktrees löschen</x:String>
504-
<x:String x:Key="Text.PruneWorktrees.Tip" xml:space="preserve">Worktree Informationen in `$GIT_DIR/worktrees` löschen</x:String>
504+
<x:String x:Key="Text.PruneWorktrees.Tip" xml:space="preserve">Worktree Informationen in `$GIT_COMMON_DIR/worktrees` löschen</x:String>
505505
<x:String x:Key="Text.Pull" xml:space="preserve">Pull</x:String>
506506
<x:String x:Key="Text.Pull.Branch" xml:space="preserve">Remote-Branch:</x:String>
507507
<x:String x:Key="Text.Pull.FetchAllBranches" xml:space="preserve">Alle Branches fetchen</x:String>

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@
504504
<x:String x:Key="Text.PruneRemote" xml:space="preserve">Prune Remote</x:String>
505505
<x:String x:Key="Text.PruneRemote.Target" xml:space="preserve">Target:</x:String>
506506
<x:String x:Key="Text.PruneWorktrees" xml:space="preserve">Prune Worktrees</x:String>
507-
<x:String x:Key="Text.PruneWorktrees.Tip" xml:space="preserve">Prune worktree information in `$GIT_DIR/worktrees`</x:String>
507+
<x:String x:Key="Text.PruneWorktrees.Tip" xml:space="preserve">Prune worktree information in `$GIT_COMMON_DIR/worktrees`</x:String>
508508
<x:String x:Key="Text.Pull" xml:space="preserve">Pull</x:String>
509509
<x:String x:Key="Text.Pull.Branch" xml:space="preserve">Remote Branch:</x:String>
510510
<x:String x:Key="Text.Pull.FetchAllBranches" xml:space="preserve">Fetch all branches</x:String>

src/Resources/Locales/es_ES.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@
508508
<x:String x:Key="Text.PruneRemote" xml:space="preserve">Podar Remoto</x:String>
509509
<x:String x:Key="Text.PruneRemote.Target" xml:space="preserve">Destino:</x:String>
510510
<x:String x:Key="Text.PruneWorktrees" xml:space="preserve">Podar Worktrees</x:String>
511-
<x:String x:Key="Text.PruneWorktrees.Tip" xml:space="preserve">Podar información de worktree en `$GIT_DIR/worktrees`</x:String>
511+
<x:String x:Key="Text.PruneWorktrees.Tip" xml:space="preserve">Podar información de worktree en `$GIT_COMMON_DIR/worktrees`</x:String>
512512
<x:String x:Key="Text.Pull" xml:space="preserve">Pull</x:String>
513513
<x:String x:Key="Text.Pull.Branch" xml:space="preserve">Rama Remota:</x:String>
514514
<x:String x:Key="Text.Pull.FetchAllBranches" xml:space="preserve">Fetch todas las ramas</x:String>

src/Resources/Locales/fr_FR.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@
476476
<x:String x:Key="Text.PruneRemote" xml:space="preserve">Élaguer une branche distant</x:String> <!-- If it is indeed about a branch -->
477477
<x:String x:Key="Text.PruneRemote.Target" xml:space="preserve">Cible :</x:String>
478478
<x:String x:Key="Text.PruneWorktrees" xml:space="preserve">Élaguer les Worktrees</x:String>
479-
<x:String x:Key="Text.PruneWorktrees.Tip" xml:space="preserve"> Élaguer les information de worktree dans `$GIT_DIR/worktrees`</x:String>
479+
<x:String x:Key="Text.PruneWorktrees.Tip" xml:space="preserve"> Élaguer les information de worktree dans `$GIT_COMMON_DIR/worktrees`</x:String>
480480
<x:String x:Key="Text.Pull" xml:space="preserve">Pull</x:String>
481481
<x:String x:Key="Text.Pull.Branch" xml:space="preserve">Branche distante :</x:String>
482482
<x:String x:Key="Text.Pull.FetchAllBranches" xml:space="preserve">Fetch toutes les branches</x:String>

src/Resources/Locales/it_IT.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@
507507
<x:String x:Key="Text.PruneRemote" xml:space="preserve">Potatura Remota</x:String>
508508
<x:String x:Key="Text.PruneRemote.Target" xml:space="preserve">Destinazione:</x:String>
509509
<x:String x:Key="Text.PruneWorktrees" xml:space="preserve">Potatura Worktrees</x:String>
510-
<x:String x:Key="Text.PruneWorktrees.Tip" xml:space="preserve">Potatura delle informazioni di worktree in `$GIT_DIR/worktrees`</x:String>
510+
<x:String x:Key="Text.PruneWorktrees.Tip" xml:space="preserve">Potatura delle informazioni di worktree in `$GIT_COMMON_DIR/worktrees`</x:String>
511511
<x:String x:Key="Text.Pull" xml:space="preserve">Scarica</x:String>
512512
<x:String x:Key="Text.Pull.Branch" xml:space="preserve">Branch Remoto:</x:String>
513513
<x:String x:Key="Text.Pull.FetchAllBranches" xml:space="preserve">Recupera tutti i branch</x:String>

src/Resources/Locales/pt_BR.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@
490490
<x:String x:Key="Text.PruneRemote" xml:space="preserve">Prunar Remoto</x:String>
491491
<x:String x:Key="Text.PruneRemote.Target" xml:space="preserve">Alvo:</x:String>
492492
<x:String x:Key="Text.PruneWorktrees" xml:space="preserve">Podar Worktrees</x:String>
493-
<x:String x:Key="Text.PruneWorktrees.Tip" xml:space="preserve">Podar informações de worktree em `$GIT_DIR/worktrees`</x:String>
493+
<x:String x:Key="Text.PruneWorktrees.Tip" xml:space="preserve">Podar informações de worktree em `$GIT_COMMON_DIR/worktrees`</x:String>
494494
<x:String x:Key="Text.Pull" xml:space="preserve">Puxar</x:String>
495495
<x:String x:Key="Text.Pull.Branch" xml:space="preserve">Branch Remoto:</x:String>
496496
<x:String x:Key="Text.Pull.FetchAllBranches" xml:space="preserve">Buscar todos os branches</x:String>

src/Resources/Locales/ru_RU.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@
508508
<x:String x:Key="Text.PruneRemote" xml:space="preserve">Удалить внешний репозиторий</x:String>
509509
<x:String x:Key="Text.PruneRemote.Target" xml:space="preserve">Цель:</x:String>
510510
<x:String x:Key="Text.PruneWorktrees" xml:space="preserve">Удалить рабочий каталог</x:String>
511-
<x:String x:Key="Text.PruneWorktrees.Tip" xml:space="preserve">Информация об обрезке рабочего каталога в «$GIT_DIR/worktrees»</x:String>
511+
<x:String x:Key="Text.PruneWorktrees.Tip" xml:space="preserve">Информация об обрезке рабочего каталога в «$GIT_COMMON_DIR/worktrees»</x:String>
512512
<x:String x:Key="Text.Pull" xml:space="preserve">Забрать</x:String>
513513
<x:String x:Key="Text.Pull.Branch" xml:space="preserve">Ветка внешнего репозитория:</x:String>
514514
<x:String x:Key="Text.Pull.FetchAllBranches" xml:space="preserve">Извлечь все ветки</x:String>

0 commit comments

Comments
 (0)