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

@@ -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()