code_review: PR #1660

Since `$GIT_DIR` is the same with `$GIT_COMMON_DIR` for submodules, use `$GIT_DIR` directly to ignore submodule's main worktree  while querying worktrees

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2025-08-04 20:35:24 +08:00
parent 6cad70db24
commit 6ddbc6f92a
3 changed files with 33 additions and 21 deletions

View File

@@ -30,26 +30,32 @@ namespace SourceGit.Commands
last = new Models.Worktree() { FullPath = line.Substring(9).Trim() };
last.RelativePath = Path.GetRelativePath(WorkingDirectory, last.FullPath);
worktrees.Add(last);
continue;
}
else if (line.StartsWith("bare", StringComparison.Ordinal))
if (last == null)
continue;
if (line.StartsWith("bare", StringComparison.Ordinal))
{
last!.IsBare = true;
worktrees.Remove(last);
last = null;
}
else if (line.StartsWith("HEAD ", StringComparison.Ordinal))
{
last!.Head = line.Substring(5).Trim();
last.Head = line.Substring(5).Trim();
}
else if (line.StartsWith("branch ", StringComparison.Ordinal))
{
last!.Branch = line.Substring(7).Trim();
last.Branch = line.Substring(7).Trim();
}
else if (line.StartsWith("detached", StringComparison.Ordinal))
{
last!.IsDetached = true;
last.IsDetached = true;
}
else if (line.StartsWith("locked", StringComparison.Ordinal))
{
last!.IsLocked = true;
last.IsLocked = true;
}
}
}

View File

@@ -9,7 +9,6 @@ namespace SourceGit.Models
public string FullPath { get; set; } = string.Empty;
public string RelativePath { get; set; } = string.Empty;
public string Head { get; set; } = string.Empty;
public bool IsBare { get; set; } = false;
public bool IsDetached { get; set; } = false;
public bool IsLocked

View File

@@ -1219,25 +1219,32 @@ namespace SourceGit.ViewModels
public void RefreshWorktrees()
{
var worktrees = new Commands.Worktree(_fullpath).ReadAllAsync().Result;
string commonDir = null;
if (worktrees.Count > 0)
commonDir = new Commands.QueryGitCommonDir(_fullpath).GetResultAsync().Result;
var cleaned = new List<Models.Worktree>();
foreach (var worktree in worktrees)
{
if (worktree.IsBare || worktree.FullPath.Equals(_fullpath))
continue;
if (!string.IsNullOrEmpty(commonDir) && worktree.FullPath.Equals(commonDir))
continue;
var cleaned = new List<Models.Worktree>();
var normalizedGitDir = _gitDir.Replace('\\', '/');
cleaned.Add(worktree);
foreach (var worktree in worktrees)
{
if (worktree.FullPath.Equals(_fullpath, StringComparison.Ordinal) ||
worktree.FullPath.Equals(normalizedGitDir, StringComparison.Ordinal))
continue;
cleaned.Add(worktree);
}
Dispatcher.UIThread.Invoke(() =>
{
Worktrees = cleaned;
});
}
Dispatcher.UIThread.Invoke(() =>
else
{
Worktrees = cleaned;
});
Dispatcher.UIThread.Invoke(() =>
{
Worktrees = worktrees;
});
}
}
public void RefreshTags()