aboutsummaryrefslogtreecommitdiffstats
path: root/lib/pama/init.go
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-11-24 16:03:01 +0100
committerRobin Jarry <robin@jarry.cc>2023-12-30 15:42:09 +0100
commitf98382d1dfc8970d3006fcc2175dd514bf7e07d0 (patch)
tree506a085a962d6d83ac223a2ad43e98a27afcc0f9 /lib/pama/init.go
parent07c1cefcf62dbd094b6f97061c469264ee089898 (diff)
downloadaerc-f98382d1dfc8970d3006fcc2175dd514bf7e07d0.tar.gz
patch/init: add init sub-cmd
Implement the :patch init command to initialize a new project. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/pama/init.go')
-rw-r--r--lib/pama/init.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/pama/init.go b/lib/pama/init.go
new file mode 100644
index 00000000..cfb9c896
--- /dev/null
+++ b/lib/pama/init.go
@@ -0,0 +1,34 @@
+package pama
+
+import (
+ "git.sr.ht/~rjarry/aerc/lib/pama/models"
+)
+
+// Init creats a new revision control project
+func (m PatchManager) Init(name, path string, overwrite bool) error {
+ id, root, err := m.detect(path)
+ if err != nil {
+ return err
+ }
+ rc, err := m.rc(id, root)
+ if err != nil {
+ return err
+ }
+ headID, err := rc.Head()
+ if err != nil {
+ return err
+ }
+ p := models.Project{
+ Name: name,
+ Root: root,
+ RevctrlID: id,
+ Base: models.NewCommit(rc, headID, ""),
+ Commits: make([]models.Commit, 0),
+ }
+ store := m.store()
+ err = store.StoreProject(p, overwrite)
+ if err != nil {
+ return storeErr(err)
+ }
+ return storeErr(store.SetCurrent(name))
+}