summaryrefslogtreecommitdiffstats
path: root/pkg/commands/models/branch.go
blob: 1bf7369d95e7886b47a089275fd880578d4176d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
	UpstreamGone bool
	Head         bool
	// 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
}

func (b *Branch) RefName() string {
	return b.Name
}

func (b *Branch) ParentRefName() string {
	return b.RefName() + "^"
}

func (b *Branch) ID() string {
	return b.RefName()
}

func (b *Branch) Description() string {
	return b.RefName()
}

func (b *Branch) IsTrackingRemote() bool {
	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 != "?"
}

func (b *Branch) RemoteBranchNotStoredLocally() bool {
	return b.IsTrackingRemote() && b.Pushables == "?" && b.Pullables == "?"
}

func (b *Branch) MatchesUpstream() bool {
	return b.RemoteBranchStoredLocally() && b.Pushables == "0" && b.Pullables == "0"
}

func (b *Branch) HasCommitsToPush() bool {
	return b.RemoteBranchStoredLocally() && b.Pushables != "0"
}

func (b *Branch) HasCommitsToPull() bool {
	return b.RemoteBranchStoredLocally() && b.Pullables != "0"
}

// for when we're in a detached head state
func (b *Branch) IsRealBranch() bool {
	return b.Pushables != "" && b.Pullables != ""
}