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'
|
|
|
|
DisplayName string
|
2020-03-17 12:22:07 +02:00
|
|
|
Recency string
|
|
|
|
Pushables string
|
|
|
|
Pullables string
|
|
|
|
UpstreamName string
|
2020-03-19 03:04:17 +02:00
|
|
|
Head bool
|
2018-08-10 13:33:49 +02:00
|
|
|
}
|
2020-08-19 14:57:22 +02:00
|
|
|
|
|
|
|
func (b *Branch) RefName() string {
|
|
|
|
return b.Name
|
|
|
|
}
|
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
|
|
|
|
|
|
|
// this method does not consider the case where the git config states that a branch is tracking the config.
|
|
|
|
// The Pullables value here is based on whether or not we saw an upstream when doing `git branch`
|
|
|
|
func (b *Branch) IsTrackingRemote() bool {
|
|
|
|
return b.IsRealBranch() && b.Pullables != "?"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Branch) MatchesUpstream() bool {
|
|
|
|
return b.IsRealBranch() && b.Pushables == "0" && b.Pullables == "0"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Branch) HasCommitsToPush() bool {
|
|
|
|
return b.IsRealBranch() && b.Pushables != "0"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Branch) HasCommitsToPull() bool {
|
|
|
|
return b.IsRealBranch() && b.Pullables != "0"
|
|
|
|
}
|
|
|
|
|
|
|
|
// for when we're in a detached head state
|
|
|
|
func (b *Branch) IsRealBranch() bool {
|
|
|
|
return b.Pushables != "" && b.Pullables != ""
|
|
|
|
}
|