2020-09-29 10:34:01 +02:00
|
|
|
package models
|
2018-08-10 13:33:49 +02:00
|
|
|
|
2018-08-13 12:26:02 +02:00
|
|
|
// Branch : A git branch
|
|
|
|
// duplicating this for now
|
|
|
|
type Branch struct {
|
2020-03-26 11:29:35 +02:00
|
|
|
Name string
|
|
|
|
// the displayname is something like '(HEAD detached at 123asdf)', whereas in that case the name would be '123asdf'
|
2022-11-07 07:35:36 +02:00
|
|
|
DisplayName string
|
|
|
|
// indicator of when the branch was last checked out e.g. '2d', '3m'
|
|
|
|
Recency string
|
|
|
|
// how many commits ahead we are from the remote branch (how many commits we can push)
|
|
|
|
Pushables string
|
|
|
|
// how many commits behind we are from the remote branch (how many commits we can pull)
|
|
|
|
Pullables string
|
|
|
|
// whether the remote branch is 'gone' i.e. we're tracking a remote branch that has been deleted
|
2022-03-24 08:49:25 +02:00
|
|
|
UpstreamGone bool
|
2022-11-07 07:35:36 +02:00
|
|
|
// whether this is the current branch. Exactly one branch should have this be true
|
2022-03-24 08:49:25 +02:00
|
|
|
Head bool
|
2022-10-16 14:31:42 +02:00
|
|
|
DetachedHead bool
|
2022-01-15 05:20:09 +02:00
|
|
|
// if we have a named remote locally this will be the name of that remote e.g.
|
|
|
|
// 'origin' or 'tiwood'. If we don't have the remote locally it'll look like
|
|
|
|
// 'git@github.com:tiwood/lazygit.git'
|
|
|
|
UpstreamRemote string
|
|
|
|
UpstreamBranch string
|
2022-11-07 07:35:36 +02:00
|
|
|
// subject line in commit message
|
|
|
|
Subject string
|
|
|
|
// commit hash
|
|
|
|
CommitHash string
|
2018-08-10 13:33:49 +02:00
|
|
|
}
|
2020-08-19 14:57:22 +02:00
|
|
|
|
2022-05-12 12:16:58 +02:00
|
|
|
func (b *Branch) FullRefName() string {
|
2022-10-16 14:31:42 +02:00
|
|
|
if b.DetachedHead {
|
|
|
|
return b.Name
|
|
|
|
}
|
2022-05-12 12:16:58 +02:00
|
|
|
return "refs/heads/" + b.Name
|
|
|
|
}
|
|
|
|
|
2020-08-19 14:57:22 +02:00
|
|
|
func (b *Branch) RefName() string {
|
|
|
|
return b.Name
|
|
|
|
}
|
2020-08-22 01:01:14 +02:00
|
|
|
|
2022-03-26 15:18:08 +02:00
|
|
|
func (b *Branch) ParentRefName() string {
|
|
|
|
return b.RefName() + "^"
|
|
|
|
}
|
|
|
|
|
2020-08-22 01:01:14 +02:00
|
|
|
func (b *Branch) ID() string {
|
|
|
|
return b.RefName()
|
|
|
|
}
|
2020-08-22 02:14:53 +02:00
|
|
|
|
|
|
|
func (b *Branch) Description() string {
|
|
|
|
return b.RefName()
|
|
|
|
}
|
2021-06-05 07:56:50 +02:00
|
|
|
|
|
|
|
func (b *Branch) IsTrackingRemote() bool {
|
2022-01-15 05:20:09 +02:00
|
|
|
return b.UpstreamRemote != ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// we know that the remote branch is not stored locally based on our pushable/pullable
|
|
|
|
// count being question marks.
|
|
|
|
func (b *Branch) RemoteBranchStoredLocally() bool {
|
|
|
|
return b.IsTrackingRemote() && b.Pushables != "?" && b.Pullables != "?"
|
2021-06-05 07:56:50 +02:00
|
|
|
}
|
|
|
|
|
2022-04-18 02:44:45 +02:00
|
|
|
func (b *Branch) RemoteBranchNotStoredLocally() bool {
|
|
|
|
return b.IsTrackingRemote() && b.Pushables == "?" && b.Pullables == "?"
|
|
|
|
}
|
|
|
|
|
2021-06-05 07:56:50 +02:00
|
|
|
func (b *Branch) MatchesUpstream() bool {
|
2022-01-15 05:20:09 +02:00
|
|
|
return b.RemoteBranchStoredLocally() && b.Pushables == "0" && b.Pullables == "0"
|
2021-06-05 07:56:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Branch) HasCommitsToPush() bool {
|
2022-01-15 05:20:09 +02:00
|
|
|
return b.RemoteBranchStoredLocally() && b.Pushables != "0"
|
2021-06-05 07:56:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Branch) HasCommitsToPull() bool {
|
2022-01-15 05:20:09 +02:00
|
|
|
return b.RemoteBranchStoredLocally() && b.Pullables != "0"
|
2021-06-05 07:56:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// for when we're in a detached head state
|
|
|
|
func (b *Branch) IsRealBranch() bool {
|
|
|
|
return b.Pushables != "" && b.Pullables != ""
|
|
|
|
}
|