summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2024-05-17 20:14:45 +0200
committerStefan Haller <stefan@haller-berlin.de>2024-05-19 09:44:38 +0200
commit0aba686f97f537301a545c888393a65b922478d2 (patch)
tree8f798cbe25d3492d0c223bbcae02a84c3ac2f6f3 /pkg
parentb91b40ba4d8d969d92228829481c2b517aa124d2 (diff)
Rename Pushables/Pullables to AheadForPull/BehindForPull
In preparation for adding AheadForPush/BehindForPush in the next commit.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/git_commands/branch_loader.go24
-rw-r--r--pkg/commands/git_commands/branch_loader_test.go76
-rw-r--r--pkg/commands/models/branch.go22
-rw-r--r--pkg/gui/controllers/branches_controller.go2
-rw-r--r--pkg/gui/controllers/sync_controller.go4
-rw-r--r--pkg/gui/presentation/branches.go8
-rw-r--r--pkg/gui/presentation/branches_test.go24
-rw-r--r--pkg/gui/services/custom_commands/models.go6
-rw-r--r--pkg/gui/services/custom_commands/session_state_loader.go6
9 files changed, 88 insertions, 84 deletions
diff --git a/pkg/commands/git_commands/branch_loader.go b/pkg/commands/git_commands/branch_loader.go
index 198368502..f1c68cd53 100644
--- a/pkg/commands/git_commands/branch_loader.go
+++ b/pkg/commands/git_commands/branch_loader.go
@@ -199,7 +199,7 @@ func obtainBranch(split []string, storeCommitDateAsRecency bool) *models.Branch
commitDate := split[6]
name := strings.TrimPrefix(fullName, "heads/")
- pushables, pullables, gone := parseUpstreamInfo(upstreamName, track)
+ aheadForPull, behindForPull, gone := parseUpstreamInfo(upstreamName, track)
recency := ""
if storeCommitDateAsRecency {
@@ -209,14 +209,14 @@ func obtainBranch(split []string, storeCommitDateAsRecency bool) *models.Branch
}
return &models.Branch{
- Name: name,
- Recency: recency,
- Pushables: pushables,
- Pullables: pullables,
- UpstreamGone: gone,
- Head: headMarker == "*",
- Subject: subject,
- CommitHash: commitHash,
+ Name: name,
+ Recency: recency,
+ AheadForPull: aheadForPull,
+ BehindForPull: behindForPull,
+ UpstreamGone: gone,
+ Head: headMarker == "*",
+ Subject: subject,
+ CommitHash: commitHash,
}
}
@@ -232,10 +232,10 @@ func parseUpstreamInfo(upstreamName string, track string) (string, string, bool)
return "?", "?", true
}
- pushables := parseDifference(track, `ahead (\d+)`)
- pullables := parseDifference(track, `behind (\d+)`)
+ ahead := parseDifference(track, `ahead (\d+)`)
+ behind := parseDifference(track, `behind (\d+)`)
- return pushables, pullables, false
+ return ahead, behind, false
}
func parseDifference(track string, regexStr string) string {
diff --git a/pkg/commands/git_commands/branch_loader_test.go b/pkg/commands/git_commands/branch_loader_test.go
index 9e56666fe..e9b8001b5 100644
--- a/pkg/commands/git_commands/branch_loader_test.go
+++ b/pkg/commands/git_commands/branch_loader_test.go
@@ -28,12 +28,12 @@ func TestObtainBranch(t *testing.T) {
input: []string{"", "heads/a_branch", "", "", "subject", "123", timeStamp},
storeCommitDateAsRecency: false,
expectedBranch: &models.Branch{
- Name: "a_branch",
- Pushables: "?",
- Pullables: "?",
- Head: false,
- Subject: "subject",
- CommitHash: "123",
+ Name: "a_branch",
+ AheadForPull: "?",
+ BehindForPull: "?",
+ Head: false,
+ Subject: "subject",
+ CommitHash: "123",
},
},
{
@@ -41,12 +41,12 @@ func TestObtainBranch(t *testing.T) {
input: []string{"", "a_branch", "", "", "subject", "123", timeStamp},
storeCommitDateAsRecency: false,
expectedBranch: &models.Branch{
- Name: "a_branch",
- Pushables: "?",
- Pullables: "?",
- Head: false,
- Subject: "subject",
- CommitHash: "123",
+ Name: "a_branch",
+ AheadForPull: "?",
+ BehindForPull: "?",
+ Head: false,
+ Subject: "subject",
+ CommitHash: "123",
},
},
{
@@ -54,12 +54,12 @@ func TestObtainBranch(t *testing.T) {
input: []string{"*", "a_branch", "", "", "subject", "123", timeStamp},
storeCommitDateAsRecency: false,
expectedBranch: &models.Branch{
- Name: "a_branch",
- Pushables: "?",
- Pullables: "?",
- Head: true,
- Subject: "subject",
- CommitHash: "123",
+ Name: "a_branch",
+ AheadForPull: "?",
+ BehindForPull: "?",
+ Head: true,
+ Subject: "subject",
+ CommitHash: "123",
},
},
{
@@ -67,12 +67,12 @@ func TestObtainBranch(t *testing.T) {
input: []string{"", "a_branch", "a_remote/a_branch", "[behind 2, ahead 3]", "subject", "123", timeStamp},
storeCommitDateAsRecency: false,
expectedBranch: &models.Branch{
- Name: "a_branch",
- Pushables: "3",
- Pullables: "2",
- Head: false,
- Subject: "subject",
- CommitHash: "123",
+ Name: "a_branch",
+ AheadForPull: "3",
+ BehindForPull: "2",
+ Head: false,
+ Subject: "subject",
+ CommitHash: "123",
},
},
{
@@ -80,13 +80,13 @@ func TestObtainBranch(t *testing.T) {
input: []string{"", "a_branch", "a_remote/a_branch", "[gone]", "subject", "123", timeStamp},
storeCommitDateAsRecency: false,
expectedBranch: &models.Branch{
- Name: "a_branch",
- UpstreamGone: true,
- Pushables: "?",
- Pullables: "?",
- Head: false,
- Subject: "subject",
- CommitHash: "123",
+ Name: "a_branch",
+ UpstreamGone: true,
+ AheadForPull: "?",
+ BehindForPull: "?",
+ Head: false,
+ Subject: "subject",
+ CommitHash: "123",
},
},
{
@@ -94,13 +94,13 @@ func TestObtainBranch(t *testing.T) {
input: []string{"", "a_branch", "", "", "subject", "123", timeStamp},
storeCommitDateAsRecency: true,
expectedBranch: &models.Branch{
- Name: "a_branch",
- Recency: "2h",
- Pushables: "?",
- Pullables: "?",
- Head: false,
- Subject: "subject",
- CommitHash: "123",
+ Name: "a_branch",
+ Recency: "2h",
+ AheadForPull: "?",
+ BehindForPull: "?",
+ Head: false,
+ Subject: "subject",
+ CommitHash: "123",
},
},
}
diff --git a/pkg/commands/models/branch.go b/pkg/commands/models/branch.go
index c5fcfdaed..9e4772410 100644
--- a/pkg/commands/models/branch.go
+++ b/pkg/commands/models/branch.go
@@ -10,10 +10,10 @@ 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
// 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
@@ -80,26 +80,26 @@ 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) HasCommitsToPush() bool {
- return b.RemoteBranchStoredLocally() && b.Pushables != "0"
+func (b *Branch) IsAheadForPull() bool {
+ return b.RemoteBranchStoredLocally() && b.AheadForPull != "0"
}
-func (b *Branch) HasCommitsToPull() bool {
- return b.RemoteBranchStoredLocally() && b.Pullables != "0"
+func (b *Branch) IsBehindForPull() bool {
+ return b.RemoteBranchStoredLocally() && b.BehindForPull != "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/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go
index b08ddd0cd..d7faa7811 100644
--- a/pkg/gui/controllers/branches_controller.go
+++ b/pkg/gui/controllers/branches_controller.go
@@ -620,7 +620,7 @@ func (self *BranchesController) fastForward(branch *models.Branch) error {
if !branch.RemoteBranchStoredLocally() {
return errors.New(self.c.Tr.FwdNoLocalUpstream)
}
- if branch.HasCommitsToPush() {
+ if branch.IsAheadForPull() {
return errors.New(self.c.Tr.FwdCommitsToPush)
}
diff --git a/pkg/gui/controllers/sync_controller.go b/pkg/gui/controllers/sync_controller.go
index 403f31d94..8bd8dac9a 100644
--- a/pkg/gui/controllers/sync_controller.go
+++ b/pkg/gui/controllers/sync_controller.go
@@ -87,10 +87,10 @@ func (self *SyncController) branchCheckedOut(f func(*models.Branch) error) func(
}
func (self *SyncController) push(currentBranch *models.Branch) error {
- // if we have pullables we'll ask if the user wants to force push
+ // if we are behind our upstream branch we'll ask if the user wants to force push
if currentBranch.IsTrackingRemote() {
opts := pushOpts{}
- if currentBranch.HasCommitsToPull() {
+ if currentBranch.IsBehindForPull() {
return self.requestToForcePush(currentBranch, opts)
} else {
return self.pushAux(currentBranch, opts)
diff --git a/pkg/gui/presentation/branches.go b/pkg/gui/presentation/branches.go
index 0abf2d4cd..406a580d5 100644
--- a/pkg/gui/presentation/branches.go
+++ b/pkg/gui/presentation/branches.go
@@ -196,11 +196,11 @@ func BranchStatus(
}
result := ""
- if branch.HasCommitsToPush() {
- result = fmt.Sprintf("ā†‘%s", branch.Pushables)
+ if branch.IsAheadForPull() {
+ result = fmt.Sprintf("ā†‘%s", branch.AheadForPull)
}
- if branch.HasCommitsToPull() {
- result = fmt.Sprintf("%sā†“%s", result, branch.Pullables)
+ if branch.IsBehindForPull() {
+ result = fmt.Sprintf("%sā†“%s", result, branch.BehindForPull)
}
return result
diff --git a/pkg/gui/presentation/branches_test.go b/pkg/gui/presentation/branches_test.go
index 250b143e3..cf2f1d994 100644
--- a/pkg/gui/presentation/branches_test.go
+++ b/pkg/gui/presentation/branches_test.go
@@ -58,8 +58,8 @@ func Test_getBranchDisplayStrings(t *testing.T) {
Name: "branch_name",
Recency: "1m",
UpstreamRemote: "origin",
- Pushables: "0",
- Pullables: "0",
+ AheadForPull: "0",
+ BehindForPull: "0",
},
itemOperation: types.ItemOperationNone,
fullDescription: false,
@@ -73,8 +73,8 @@ func Test_getBranchDisplayStrings(t *testing.T) {
Name: "branch_name",
Recency: "1m",
UpstreamRemote: "origin",
- Pushables: "3",
- Pullables: "5",
+ AheadForPull: "3",
+ BehindForPull: "5",
},
itemOperation: types.ItemOperationNone,
fullDescription: false,
@@ -99,8 +99,8 @@ func Test_getBranchDisplayStrings(t *testing.T) {
CommitHash: "1234567890",
UpstreamRemote: "origin",
UpstreamBranch: "branch_name",
- Pushables: "0",
- Pullables: "0",
+ AheadForPull: "0",
+ BehindForPull: "0",
Subject: "commit title",
},
itemOperation: types.ItemOperationNone,
@@ -144,8 +144,8 @@ func Test_getBranchDisplayStrings(t *testing.T) {
Name: "branch_name",
Recency: "1m",
UpstreamRemote: "origin",
- Pushables: "0",
- Pullables: "0",
+ AheadForPull: "0",
+ BehindForPull: "0",
},
itemOperation: types.ItemOperationNone,
fullDescription: false,
@@ -159,8 +159,8 @@ func Test_getBranchDisplayStrings(t *testing.T) {
Name: "branch_name",
Recency: "1m",
UpstreamRemote: "origin",
- Pushables: "3",
- Pullables: "5",
+ AheadForPull: "3",
+ BehindForPull: "5",
},
itemOperation: types.ItemOperationNone,
fullDescription: false,
@@ -212,8 +212,8 @@ func Test_getBranchDisplayStrings(t *testing.T) {
CommitHash: "1234567890",
UpstreamRemote: "origin",
UpstreamBranch: "branch_name",
- Pushables: "0",
- Pullables: "0",
+ AheadForPull: "0",
+ BehindForPull: "0",
Subject: "commit title",
},
itemOperation: types.ItemOperationNone,
diff --git a/pkg/gui/services/custom_commands/models.go b/pkg/gui/services/custom_commands/models.go
index a33a4daf8..bd3a69224 100644
--- a/pkg/gui/services/custom_commands/models.go
+++ b/pkg/gui/services/custom_commands/models.go
@@ -47,8 +47,10 @@ type Branch struct {
Name string
DisplayName string
Recency string
- Pushables string
- Pullables string
+ Pushables string // deprecated: use AheadForPull
+ Pullables string // deprecated: use BehindForPull
+ AheadForPull string
+ BehindForPull string
UpstreamGone bool
Head bool
DetachedHead bool
diff --git a/pkg/gui/services/custom_commands/session_state_loader.go b/pkg/gui/services/custom_commands/session_state_loader.go
index 23369cb0b..81d30e5bf 100644
--- a/pkg/gui/services/custom_commands/session_state_loader.go
+++ b/pkg/gui/services/custom_commands/session_state_loader.go
@@ -71,8 +71,10 @@ func branchShimFromModelBranch(branch *models.Branch) *Branch {
Name: branch.Name,
DisplayName: branch.DisplayName,
Recency: branch.Recency,
- Pushables: branch.Pushables,
- Pullables: branch.Pullables,
+ Pushables: branch.AheadForPull,
+ Pullables: branch.BehindForPull,
+ AheadForPull: branch.AheadForPull,
+ BehindForPull: branch.BehindForPull,
UpstreamGone: branch.UpstreamGone,
Head: branch.Head,
DetachedHead: branch.DetachedHead,