diff options
author | Koni Marti <koni.marti@gmail.com> | 2023-11-24 16:03:04 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-12-30 15:42:09 +0100 |
commit | 41e066768c18268fe3deecc60b5797e26f44cf4e (patch) | |
tree | e3e14165ef3a5308d9205bc8f6d4f1831ec654c8 /commands | |
parent | cf47763e5582563f712b4a40a9b299378aba9003 (diff) | |
download | aerc-41e066768c18268fe3deecc60b5797e26f44cf4e.tar.gz |
patch/remove: add remove sub-cmd
Implement the :patch remove command. Remove a patch set from the
respository and from the internal storage. Note that in git, this will
change all commit hashes that appear after the removed one since the
commit hash depends on its parents. Adjust the code to handle such cases
and add tests for this.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands')
-rw-r--r-- | commands/patch/remove.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/commands/patch/remove.go b/commands/patch/remove.go new file mode 100644 index 00000000..6697177b --- /dev/null +++ b/commands/patch/remove.go @@ -0,0 +1,43 @@ +package patch + +import ( + "fmt" + "time" + + "git.sr.ht/~rjarry/aerc/app" + "git.sr.ht/~rjarry/aerc/commands" + "git.sr.ht/~rjarry/aerc/lib/pama" + "git.sr.ht/~rjarry/aerc/log" +) + +type Remove struct { + Tag string `opt:"tag" complete:"CompleteTag"` +} + +func init() { + register(Remove{}) +} + +func (Remove) Aliases() []string { + return []string{"remove"} +} + +func (*Remove) CompleteTag(arg string) []string { + patches, err := pama.New().CurrentPatches() + if err != nil { + log.Errorf("failed to get current patches: %v", err) + return nil + } + return commands.FilterList(patches, arg, nil) +} + +func (r Remove) Execute(args []string) error { + patch := r.Tag + err := pama.New().RemovePatch(patch) + if err != nil { + return err + } + app.PushStatus(fmt.Sprintf("Patch %s has been removed", patch), + 10*time.Second) + return nil +} |