diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-09-29 20:28:39 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-09-29 20:48:49 +1000 |
commit | ce6f8ed1bcf85204aadb14d583c5f01f96ac4e49 (patch) | |
tree | 99cc821e03883c2cd7821e64b41e0d9778f51082 /pkg/commands/models | |
parent | 83748d78f875de8ddf7786e17ec59a1825a65c1f (diff) |
move models folder into commands folder
Diffstat (limited to 'pkg/commands/models')
-rw-r--r-- | pkg/commands/models/branch.go | 26 | ||||
-rw-r--r-- | pkg/commands/models/commit.go | 37 | ||||
-rw-r--r-- | pkg/commands/models/commit_file.go | 21 | ||||
-rw-r--r-- | pkg/commands/models/file.go | 60 | ||||
-rw-r--r-- | pkg/commands/models/remote.go | 20 | ||||
-rw-r--r-- | pkg/commands/models/remote_branch.go | 23 | ||||
-rw-r--r-- | pkg/commands/models/stash_entry.go | 21 | ||||
-rw-r--r-- | pkg/commands/models/submodule_config.go | 7 | ||||
-rw-r--r-- | pkg/commands/models/tag.go | 18 |
9 files changed, 233 insertions, 0 deletions
diff --git a/pkg/commands/models/branch.go b/pkg/commands/models/branch.go new file mode 100644 index 000000000..c95e335f9 --- /dev/null +++ b/pkg/commands/models/branch.go @@ -0,0 +1,26 @@ +package models + +// Branch : A git branch +// duplicating this for now +type Branch struct { + Name string + // the displayname is something like '(HEAD detached at 123asdf)', whereas in that case the name would be '123asdf' + DisplayName string + Recency string + Pushables string + Pullables string + UpstreamName string + Head bool +} + +func (b *Branch) RefName() string { + return b.Name +} + +func (b *Branch) ID() string { + return b.RefName() +} + +func (b *Branch) Description() string { + return b.RefName() +} diff --git a/pkg/commands/models/commit.go b/pkg/commands/models/commit.go new file mode 100644 index 000000000..78cf7f7f7 --- /dev/null +++ b/pkg/commands/models/commit.go @@ -0,0 +1,37 @@ +package models + +import "fmt" + +// Commit : A git commit +type Commit struct { + Sha string + Name string + Status string // one of "unpushed", "pushed", "merged", "rebasing" or "selected" + Action string // one of "", "pick", "edit", "squash", "reword", "drop", "fixup" + Tags []string + ExtraInfo string // something like 'HEAD -> master, tag: v0.15.2' + Author string + UnixTimestamp int64 + + // IsMerge tells us whether we're dealing with a merge commit i.e. a commit with two parents + IsMerge bool +} + +func (c *Commit) ShortSha() string { + if len(c.Sha) < 8 { + return c.Sha + } + return c.Sha[:8] +} + +func (c *Commit) RefName() string { + return c.Sha +} + +func (c *Commit) ID() string { + return c.RefName() +} + +func (c *Commit) Description() string { + return fmt.Sprintf("%s %s", c.Sha[:7], c.Name) +} diff --git a/pkg/commands/models/commit_file.go b/pkg/commands/models/commit_file.go new file mode 100644 index 000000000..17faf0142 --- /dev/null +++ b/pkg/commands/models/commit_file.go @@ -0,0 +1,21 @@ +package models + +// CommitFile : A git commit file +type CommitFile struct { + // Parent is the identifier of the parent object e.g. a commit SHA if this commit file is for a commit, or a stash entry ref like 'stash@{1}' + Parent string + Name string + + // PatchStatus tells us whether the file has been wholly or partially added to a patch. We might want to pull this logic up into the gui package and make it a map like we do with cherry picked commits + PatchStatus int // one of 'WHOLE' 'PART' 'NONE' + + ChangeStatus string // e.g. 'A' for added or 'M' for modified. This is based on the result from git diff --name-status +} + +func (f *CommitFile) ID() string { + return f.Name +} + +func (f *CommitFile) Description() string { + return f.Name +} diff --git a/pkg/commands/models/file.go b/pkg/commands/models/file.go new file mode 100644 index 000000000..482ba5cb5 --- /dev/null +++ b/pkg/commands/models/file.go @@ -0,0 +1,60 @@ +package models + +import ( + "strings" + + "github.com/jesseduffield/lazygit/pkg/utils" +) + +// File : A file from git status +// duplicating this for now +type File struct { + Name string + HasStagedChanges bool + HasUnstagedChanges bool + Tracked bool + Deleted bool + HasMergeConflicts bool + HasInlineMergeConflicts bool + DisplayString string + Type string // one of 'file', 'directory', and 'other' + ShortStatus string // e.g. 'AD', ' A', 'M ', '??' +} + +const RENAME_SEPARATOR = " -> " + +func (f *File) IsRename() bool { + return strings.Contains(f.Name, RENAME_SEPARATOR) +} + +// Names returns an array containing just the filename, or in the case of a rename, the after filename and the before filename +func (f *File) Names() []string { + return strings.Split(f.Name, RENAME_SEPARATOR) +} + +// returns true if the file names are the same or if a a file rename includes the filename of the other +func (f *File) Matches(f2 *File) bool { + return utils.StringArraysOverlap(f.Names(), f2.Names()) +} + +func (f *File) ID() string { + return f.Name +} + +func (f *File) Description() string { + return f.Name +} + +func (f *File) IsSubmodule(configs []*SubmoduleConfig) bool { + return f.SubmoduleConfig(configs) != nil +} + +func (f *File) SubmoduleConfig(configs []*SubmoduleConfig) *SubmoduleConfig { + for _, config := range configs { + if f.Name == config.Name { + return config + } + } + + return nil +} diff --git a/pkg/commands/models/remote.go b/pkg/commands/models/remote.go new file mode 100644 index 000000000..42ebe16ab --- /dev/null +++ b/pkg/commands/models/remote.go @@ -0,0 +1,20 @@ +package models + +// Remote : A git remote +type Remote struct { + Name string + Urls []string + Branches []*RemoteBranch +} + +func (r *Remote) RefName() string { + return r.Name +} + +func (r *Remote) ID() string { + return r.RefName() +} + +func (r *Remote) Description() string { + return r.RefName() +} diff --git a/pkg/commands/models/remote_branch.go b/pkg/commands/models/remote_branch.go new file mode 100644 index 000000000..bee004fdb --- /dev/null +++ b/pkg/commands/models/remote_branch.go @@ -0,0 +1,23 @@ +package models + +// Remote Branch : A git remote branch +type RemoteBranch struct { + Name string + RemoteName string +} + +func (r *RemoteBranch) FullName() string { + return r.RemoteName + "/" + r.Name +} + +func (r *RemoteBranch) RefName() string { + return r.FullName() +} + +func (r *RemoteBranch) ID() string { + return r.RefName() +} + +func (r *RemoteBranch) Description() string { + return r.RefName() +} diff --git a/pkg/commands/models/stash_entry.go b/pkg/commands/models/stash_entry.go new file mode 100644 index 000000000..efda6bc77 --- /dev/null +++ b/pkg/commands/models/stash_entry.go @@ -0,0 +1,21 @@ +package models + +import "fmt" + +// StashEntry : A git stash entry +type StashEntry struct { + Index int + Name string +} + +func (s *StashEntry) RefName() string { + return fmt.Sprintf("stash@{%d}", s.Index) +} + +func (s *StashEntry) ID() string { + return s.RefName() +} + +func (s *StashEntry) Description() string { + return s.RefName() + ": " + s.Name +} diff --git a/pkg/commands/models/submodule_config.go b/pkg/commands/models/submodule_config.go new file mode 100644 index 000000000..c6481bbd1 --- /dev/null +++ b/pkg/commands/models/submodule_config.go @@ -0,0 +1,7 @@ +package models + +type SubmoduleConfig struct { + Name string + Path string + Url string +} diff --git a/pkg/commands/models/tag.go b/pkg/commands/models/tag.go new file mode 100644 index 000000000..2fb024e66 --- /dev/null +++ b/pkg/commands/models/tag.go @@ -0,0 +1,18 @@ +package models + +// Tag : A git tag +type Tag struct { + Name string +} + +func (t *Tag) RefName() string { + return t.Name +} + +func (t *Tag) ID() string { + return t.RefName() +} + +func (t *Tag) Description() string { + return "tag " + t.Name +} |