From 6b4a6384156451203bd4559f65563f03dbbdd5df Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 16 Jul 2023 17:52:07 +1000 Subject: Handle deleting branch attached to worktree --- pkg/commands/git_commands/git_command_builder.go | 7 +++++++ pkg/commands/git_commands/worktree.go | 6 ++++++ 2 files changed, 13 insertions(+) (limited to 'pkg/commands/git_commands') diff --git a/pkg/commands/git_commands/git_command_builder.go b/pkg/commands/git_commands/git_command_builder.go index bb97f2dc6..05d788b4c 100644 --- a/pkg/commands/git_commands/git_command_builder.go +++ b/pkg/commands/git_commands/git_command_builder.go @@ -49,6 +49,13 @@ func (self *GitCommandBuilder) RepoPath(value string) *GitCommandBuilder { return self } +func (self *GitCommandBuilder) WorktreePath(path string) *GitCommandBuilder { + // worktree path comes before the command + self.args = append([]string{"--work-tree", path}, self.args...) + + return self +} + func (self *GitCommandBuilder) ToArgv() []string { return append([]string{"git"}, self.args...) } diff --git a/pkg/commands/git_commands/worktree.go b/pkg/commands/git_commands/worktree.go index 101601afb..922dbb957 100644 --- a/pkg/commands/git_commands/worktree.go +++ b/pkg/commands/git_commands/worktree.go @@ -32,6 +32,12 @@ func (self *WorktreeCommands) Delete(worktreePath string, force bool) error { return self.cmd.New(cmdArgs).Run() } +func (self *WorktreeCommands) Detach(worktreePath string) error { + cmdArgs := NewGitCmd("checkout").Arg("--detach").WorktreePath(worktreePath).ToArgv() + + return self.cmd.New(cmdArgs).Run() +} + func (self *WorktreeCommands) IsCurrentWorktree(w *models.Worktree) bool { return IsCurrentWorktree(w) } -- cgit v1.2.3