1package git23import "context"45// WorktreeAddOptions contains optional arguments for adding a worktree.6//7// Docs: https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt-add8type WorktreeAddOptions struct {9 // The new branch name to create and checkout in the worktree.10 Branch string11 CommandOptions12}1314// WorktreeAdd creates a new worktree at the given path linked to this15// repository. The commitIsh determines the HEAD of the new worktree.16func (r *Repository) WorktreeAdd(ctx context.Context, path, commitIsh string, opts ...WorktreeAddOptions) error {17 var opt WorktreeAddOptions18 if len(opts) > 0 {19 opt = opts[0]20 }2122 args := []string{"worktree", "add"}23 if opt.Branch != "" {24 args = append(args, "-b", opt.Branch)25 }26 args = append(args, "--end-of-options", path, commitIsh)2728 _, err := exec(ctx, r.path, args, opt.Envs)29 return err30}3132// WorktreeRemoveOptions contains optional arguments for removing a worktree.33//34// Docs: https://git-scm.com/docs/git-worktree#Documentation/git-worktree.txt-remove35type WorktreeRemoveOptions struct {36 // Indicates whether to force removal even if the worktree is dirty.37 Force bool38 CommandOptions39}4041// WorktreeRemove removes a worktree at the given path.42func (r *Repository) WorktreeRemove(ctx context.Context, path string, opts ...WorktreeRemoveOptions) error {43 var opt WorktreeRemoveOptions44 if len(opts) > 0 {45 opt = opts[0]46 }4748 args := []string{"worktree", "remove"}49 if opt.Force {50 args = append(args, "--force")51 }52 args = append(args, "--end-of-options", path)5354 _, err := exec(ctx, r.path, args, opt.Envs)55 return err56}