summaryrefslogtreecommitdiffstats
path: root/pkg/commands/git_commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-07-16 17:52:07 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-07-30 18:35:22 +1000
commit6b4a6384156451203bd4559f65563f03dbbdd5df (patch)
tree1674b7af6aa63b872f9928d9c39bab08adaf9716 /pkg/commands/git_commands
parent4b3c9f5b35545e3bb840e33602829c2ce945369f (diff)
Handle deleting branch attached to worktree
Diffstat (limited to 'pkg/commands/git_commands')
-rw-r--r--pkg/commands/git_commands/git_command_builder.go7
-rw-r--r--pkg/commands/git_commands/worktree.go6
2 files changed, 13 insertions, 0 deletions
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)
}