private bool CanDeleteWorkspace(WorkTree workTree) { if (workTree.IsDeleted) { return(false); } if (_worktrees.Count == 1) { return(false); } if (IsCurrentlyOpenedWorktree(workTree)) { return(false); } return(true); }
private void Initialize() { var lines = Module.GitExecutable.GetOutput("worktree list --porcelain").Split('\n').GetEnumerator(); _worktrees = new List <WorkTree>(); WorkTree currentWorktree = null; while (lines.MoveNext()) { var current = (string)lines.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); }
private bool IsCurrentlyOpenedWorktree(WorkTree workTree) { return(new DirectoryInfo(UICommands.GitModule.WorkingDir).FullName.TrimEnd('\\') == new DirectoryInfo(workTree.Path).FullName.TrimEnd('\\')); }