From f8c9e7fff564667700c3dbc239d55db8fcd032a6 Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Fri, 24 Nov 2023 16:03:10 +0100 Subject: patch: implement worktree support Implement worktree support for the patch management. Use ":patch apply -w " to create a new worktree and apply the selected messages to it. The worktree is linked to repo in the current project. Internally, the worktree is stored as a new project. When this project is deleted with ":patch delete", the underlying linked worktree is removed as well. ":patch list" shows when a project is a worktree and to what project it is linked to. Worktrees enable the users to create a new copy of the repo at a given commit and apply patches without interrupting the current work in the base repo. Signed-off-by: Koni Marti Acked-by: Robin Jarry --- lib/pama/revctrl/git.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/pama/revctrl') diff --git a/lib/pama/revctrl/git.go b/lib/pama/revctrl/git.go index f4b78dd5..7be9de58 100644 --- a/lib/pama/revctrl/git.go +++ b/lib/pama/revctrl/git.go @@ -98,6 +98,22 @@ func (g git) Clean() bool { return len(s) == 0 && exitcode == 0 && err == nil } +func (g git) CreateWorktree(target, commit string) error { + _, exitcode, err := g.do("worktree", "add", target, commit) + if exitcode > 0 { + return fmt.Errorf("failed to create worktree in %s: %w", target, err) + } + return err +} + +func (g git) DeleteWorktree(target string) error { + _, exitcode, err := g.do("worktree", "remove", target) + if exitcode > 0 { + return fmt.Errorf("failed to delete worktree in %s: %w", target, err) + } + return err +} + func (g git) ApplyCmd() string { // TODO: should we return a *exec.Cmd instead of a string? return fmt.Sprintf("git -C %s am -3 --empty drop", g.path) -- cgit