aboutsummaryrefslogtreecommitdiffstats
path: root/lib/pama/delete.go
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-11-24 16:03:10 +0100
committerRobin Jarry <robin@jarry.cc>2023-12-30 15:42:09 +0100
commitf8c9e7fff564667700c3dbc239d55db8fcd032a6 (patch)
tree2fbe2e87ed8e713e119aaadf0f2e317fb01d90fc /lib/pama/delete.go
parentcfcab6c5c883a08afa3a56c11e4f48d9725be2a0 (diff)
downloadaerc-f8c9e7fff564667700c3dbc239d55db8fcd032a6.tar.gz
patch: implement worktree support
Implement worktree support for the patch management. Use ":patch apply -w <commit-ish> <tag>" 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 <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/pama/delete.go')
-rw-r--r--lib/pama/delete.go22
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/pama/delete.go b/lib/pama/delete.go
index 18a93a27..53dbeeb1 100644
--- a/lib/pama/delete.go
+++ b/lib/pama/delete.go
@@ -1,6 +1,10 @@
package pama
-import "fmt"
+import (
+ "fmt"
+
+ "git.sr.ht/~rjarry/aerc/log"
+)
// Delete removes provided project
func (m PatchManager) Delete(name string) error {
@@ -21,8 +25,8 @@ func (m PatchManager) Delete(name string) error {
return fmt.Errorf("Project '%s' not found", name)
}
- cur, err := m.CurrentProject()
- if err == nil && cur.Name == name {
+ cur, err := store.CurrentName()
+ if err == nil && cur == name {
var next string
for _, s := range names {
if name != s {
@@ -36,6 +40,18 @@ func (m PatchManager) Delete(name string) error {
}
}
+ p, err := store.Project(name)
+ if err == nil && isWorktree(p) {
+ err = m.deleteWorktree(p)
+ if err != nil {
+ log.Errorf("failed to delete worktree: %v", err)
+ }
+ err = store.SetCurrent(p.Worktree.Name)
+ if err != nil {
+ log.Errorf("failed to set current project: %v", err)
+ }
+ }
+
return storeErr(m.store().DeleteProject(name))
}