From 4cc2e6be3a010ecfba314909ce9b594f04e1be0e Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Wed, 31 Jan 2024 17:23:00 +0100 Subject: commands: rename patch delete to patch unlink Rename the command :patch delete to :patch unlink. This expresses the "link" between the project data within aerc and the underlying repository better. :patch unlink does not delete anything in the repository, it only removes the metadata about currently applied patch revisions/tags. Signed-off-by: Koni Marti Acked-by: Robin Jarry --- lib/pama/delete.go | 61 ------------------------------------------------------ lib/pama/unlink.go | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 61 deletions(-) delete mode 100644 lib/pama/delete.go create mode 100644 lib/pama/unlink.go (limited to 'lib/pama') diff --git a/lib/pama/delete.go b/lib/pama/delete.go deleted file mode 100644 index 53dbeeb1..00000000 --- a/lib/pama/delete.go +++ /dev/null @@ -1,61 +0,0 @@ -package pama - -import ( - "fmt" - - "git.sr.ht/~rjarry/aerc/log" -) - -// Delete removes provided project -func (m PatchManager) Delete(name string) error { - store := m.store() - names, err := m.Names() - if err != nil { - return err - } - - index := -1 - for i, s := range names { - if s == name { - index = i - break - } - } - if index < 0 { - return fmt.Errorf("Project '%s' not found", name) - } - - cur, err := store.CurrentName() - if err == nil && cur == name { - var next string - for _, s := range names { - if name != s { - next = s - break - } - } - err = store.SetCurrent(next) - if err != nil { - return storeErr(err) - } - } - - 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)) -} - -func (m PatchManager) Names() ([]string, error) { - names, err := m.store().Names() - return names, storeErr(err) -} diff --git a/lib/pama/unlink.go b/lib/pama/unlink.go new file mode 100644 index 00000000..2def5403 --- /dev/null +++ b/lib/pama/unlink.go @@ -0,0 +1,61 @@ +package pama + +import ( + "fmt" + + "git.sr.ht/~rjarry/aerc/log" +) + +// Unlink removes provided project +func (m PatchManager) Unlink(name string) error { + store := m.store() + names, err := m.Names() + if err != nil { + return err + } + + index := -1 + for i, s := range names { + if s == name { + index = i + break + } + } + if index < 0 { + return fmt.Errorf("Project '%s' not found", name) + } + + cur, err := store.CurrentName() + if err == nil && cur == name { + var next string + for _, s := range names { + if name != s { + next = s + break + } + } + err = store.SetCurrent(next) + if err != nil { + return storeErr(err) + } + } + + 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)) +} + +func (m PatchManager) Names() ([]string, error) { + names, err := m.store().Names() + return names, storeErr(err) +} -- cgit