diff options
Diffstat (limited to 'lib/pama/models')
-rw-r--r-- | lib/pama/models/models.go | 20 | ||||
-rw-r--r-- | lib/pama/models/view.go | 20 |
2 files changed, 32 insertions, 8 deletions
diff --git a/lib/pama/models/models.go b/lib/pama/models/models.go index 1c098885..9b21f0f5 100644 --- a/lib/pama/models/models.go +++ b/lib/pama/models/models.go @@ -20,6 +20,15 @@ type Commit struct { Tag string } +// WorktreeParent stores the name and repo location for the base project in the +// linked worktree project. +type WorktreeParent struct { + // Name is the project name from the base repo. + Name string + // Root is the root directory of the base repo. + Root string +} + // Project contains the data to access a revision control system and to store // the internal patch tracking data. type Project struct { @@ -30,6 +39,9 @@ type Project struct { Root string // RevctrlID stores the ID for the revision control system. RevctrlID string + // Worktree keeps the base repo information. If Worktree.Name and + // Worktree.Root are not zero, this project contains a linked worktree. + Worktree WorktreeParent // Base represents the reference (base) commit. Base Commit // Commits contains the commits that are being tracked. The slice can @@ -64,6 +76,12 @@ type RevisionController interface { // ApplyCmd returns a string with an executable command that is used to // apply patches with the :pipe command. ApplyCmd() string + // CreateWorktree creats a worktree in path at commit. + CreateWorktree(path string, commit string) error + // DeleteWorktree removes the linked worktree stored in the path + // location. Note that this function should be called from the base + // repo. + DeleteWorktree(path string) error } // PersistentStorer is an interface to a persistent storage for Project structs. @@ -81,6 +99,8 @@ type PersistentStorer interface { Current() (Project, error) // Names returns a slice of Project.Name for all stored projects. Names() ([]string, error) + // Project returns the stored project for the provided name. + Project(string) (Project, error) // Projects returns all stored projects. Projects() ([]Project, error) } diff --git a/lib/pama/models/view.go b/lib/pama/models/view.go index 093ca6f0..6a5b6bd4 100644 --- a/lib/pama/models/view.go +++ b/lib/pama/models/view.go @@ -10,7 +10,7 @@ import ( ) var templateText = ` -Project {{.Name}} {{if .IsActive}}[active]{{end}} +Project {{.Name}} {{if .IsActive}}[active]{{end}} {{if .IsWorktree}}[Linked worktree to {{.WorktreeParent}}]{{end}} Directory {{.Root}} Base {{with .Base.ID}}{{if ge (len .) 40}}{{printf "%-6.6s" .}}{{else}}{{.}}{{end}}{{end}} {{$notes := .Notes}}{{$commits := .Commits}} @@ -37,17 +37,21 @@ type view struct { // the key and the annotation is the value. Notes map[string]string // IsActive is true if the current project is selected. - IsActive bool + IsActive bool + IsWorktree bool + WorktreeParent string } func newView(p Project, active bool, notes map[string]string) view { v := view{ - Name: p.Name, - Root: p.Root, - Base: p.Base, - Commits: make(map[string][]Commit), - Notes: notes, - IsActive: active, + Name: p.Name, + Root: p.Root, + Base: p.Base, + Commits: make(map[string][]Commit), + Notes: notes, + IsActive: active, + IsWorktree: p.Worktree.Root != "" && p.Worktree.Name != "", + WorktreeParent: p.Worktree.Name, } for _, commit := range p.Commits { |