diff options
Diffstat (limited to 'pkg/commands/models')
-rw-r--r-- | pkg/commands/models/branch.go | 40 | ||||
-rw-r--r-- | pkg/commands/models/commit.go | 2 |
2 files changed, 29 insertions, 13 deletions
diff --git a/pkg/commands/models/branch.go b/pkg/commands/models/branch.go index c5fcfdaed..04f869ebd 100644 --- a/pkg/commands/models/branch.go +++ b/pkg/commands/models/branch.go @@ -1,6 +1,9 @@ package models -import "fmt" +import ( + "fmt" + "sync/atomic" +) // Branch : A git branch // duplicating this for now @@ -10,10 +13,14 @@ type Branch struct { 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 ahead we are from the remote branch (how many commits we can push, assuming we push to our tracked remote branch) + AheadForPull string // how many commits behind we are from the remote branch (how many commits we can pull) - Pullables string + BehindForPull string + // how many commits ahead we are from the branch we're pushing to (which might not be the same as our upstream branch in a triangular workflow) + AheadForPush string + // how many commits behind we are from the branch we're pushing to (which might not be the same as our upstream branch in a triangular workflow) + BehindForPush string // whether the remote branch is 'gone' i.e. we're tracking a remote branch that has been deleted UpstreamGone bool // whether this is the current branch. Exactly one branch should have this be true @@ -28,6 +35,11 @@ type Branch struct { Subject string // commit hash CommitHash string + + // How far we have fallen behind our base branch. 0 means either not + // determined yet, or up to date with base branch. (We don't need to + // distinguish the two, as we don't draw anything in both cases.) + BehindBaseBranch atomic.Int32 } func (b *Branch) FullRefName() string { @@ -80,26 +92,30 @@ func (b *Branch) IsTrackingRemote() bool { // 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 != "?" + return b.IsTrackingRemote() && b.AheadForPull != "?" && b.BehindForPull != "?" } func (b *Branch) RemoteBranchNotStoredLocally() bool { - return b.IsTrackingRemote() && b.Pushables == "?" && b.Pullables == "?" + return b.IsTrackingRemote() && b.AheadForPull == "?" && b.BehindForPull == "?" } func (b *Branch) MatchesUpstream() bool { - return b.RemoteBranchStoredLocally() && b.Pushables == "0" && b.Pullables == "0" + return b.RemoteBranchStoredLocally() && b.AheadForPull == "0" && b.BehindForPull == "0" +} + +func (b *Branch) IsAheadForPull() bool { + return b.RemoteBranchStoredLocally() && b.AheadForPull != "0" } -func (b *Branch) HasCommitsToPush() bool { - return b.RemoteBranchStoredLocally() && b.Pushables != "0" +func (b *Branch) IsBehindForPull() bool { + return b.RemoteBranchStoredLocally() && b.BehindForPull != "0" } -func (b *Branch) HasCommitsToPull() bool { - return b.RemoteBranchStoredLocally() && b.Pullables != "0" +func (b *Branch) IsBehindForPush() bool { + return b.RemoteBranchStoredLocally() && b.BehindForPush != "0" } // for when we're in a detached head state func (b *Branch) IsRealBranch() bool { - return b.Pushables != "" && b.Pullables != "" + return b.AheadForPull != "" && b.BehindForPull != "" } diff --git a/pkg/commands/models/commit.go b/pkg/commands/models/commit.go index 64b89db8f..95e3b9b18 100644 --- a/pkg/commands/models/commit.go +++ b/pkg/commands/models/commit.go @@ -3,8 +3,8 @@ package models import ( "fmt" - "github.com/fsmiamoto/git-todo-parser/todo" "github.com/jesseduffield/lazygit/pkg/utils" + "github.com/stefanhaller/git-todo-parser/todo" ) // Special commit hash for empty tree object |