private void Initialize() { var listWorktree = ThreadHelper.JoinableTaskFactory.Run(() => UICommands.CommandLineCommandAsync("git", "worktree list --porcelain")); var worktreesLines = listWorktree.Split('\n').GetEnumerator(); _worktrees = new List <WorkTree>(); WorkTree currentWorktree = null; while (worktreesLines.MoveNext()) { var current = (string)worktreesLines.Current; if (string.IsNullOrWhiteSpace(current)) { continue; } var strings = current.Split(' '); if (strings[0] == "worktree") { currentWorktree = new WorkTree { Path = current.Substring(9) }; currentWorktree.IsDeleted = !Directory.Exists(currentWorktree.Path); _worktrees.Add(currentWorktree); } else if (strings[0] == "HEAD") { currentWorktree.Sha1 = strings[1]; } else { switch (strings[0]) { case "bare": currentWorktree.Type = HeadType.Bare; break; case "branch": currentWorktree.Type = HeadType.Branch; currentWorktree.Branch = strings[1]; break; case "detached": currentWorktree.Type = HeadType.Detached; break; } } } Worktrees.DataSource = _worktrees; for (var i = 0; i < Worktrees.Rows.Count; i++) { if (i == 0) { Worktrees.Rows[i].Cells["Delete"].Value = Images.Blank; if (IsCurrentlyOpenedWorktree(_worktrees[0])) { Worktrees.Rows[i].Cells["Open"].Value = Images.Blank; } } else if (!CanDeleteWorkspace(_worktrees[i])) { Worktrees.Rows[i].Cells["Open"].Value = Images.Blank; Worktrees.Rows[i].Cells["Delete"].Value = Images.Blank; } } buttonPruneWorktrees.Enabled = _worktrees.Skip(1).Any(w => w.IsDeleted); }