Skip to content

Commit c05719b

Browse files
committed
amend! Add BranchBeingRebased to Model struct
Add CheckedOutBranch to Model struct
1 parent 9c8db49 commit c05719b

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

pkg/gui/controllers/helpers/refresh_helper.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,32 @@ func (self *RefreshHelper) refreshCommits() {
249249
wg.Wait()
250250
}
251251

252+
func (self *RefreshHelper) determineCheckoutBranchName() string {
253+
if rebasedBranch := self.c.Git().Status.BranchBeingRebased(); rebasedBranch != "" {
254+
// During a rebase we're on a detached head, so cannot determine the
255+
// branch name in the usual way. We need to read it from the
256+
// ".git/rebase-merge/head-name" file instead.
257+
return strings.TrimPrefix(rebasedBranch, "refs/heads/")
258+
}
259+
260+
if bisectedBranch := self.c.Git().Bisect.GetInfo().GetStartSha(); bisectedBranch != "" {
261+
// Likewise, when we're bisecting we're on a detached head as well. In
262+
// this case we read the branch name from the ".git/BISECT_START" file.
263+
return bisectedBranch
264+
}
265+
266+
// In all other cases, get the branch name by asking git what branch is
267+
// checked out. Note that if we're on a detached head (for reasons other
268+
// than rebasing or bisecting, i.e. it was explicitly checked out), then
269+
// this will return its sha.
270+
if branchInfo, err := self.c.Git().Branch.CurrentBranchInfo(); err == nil {
271+
return branchInfo.RefName
272+
}
273+
274+
// Should never get here unless the working copy is corrupt
275+
return ""
276+
}
277+
252278
func (self *RefreshHelper) refreshCommitsWithLimit() error {
253279
self.c.Mutexes().LocalCommitsMutex.Lock()
254280
defer self.c.Mutexes().LocalCommitsMutex.Unlock()
@@ -267,7 +293,7 @@ func (self *RefreshHelper) refreshCommitsWithLimit() error {
267293
}
268294
self.c.Model().Commits = commits
269295
self.c.Model().WorkingTreeStateAtLastCommitRefresh = self.c.Git().Status.WorkingTreeState()
270-
self.c.Model().BranchBeingRebased = self.c.Git().Status.BranchBeingRebased()
296+
self.c.Model().CheckedOutBranch = self.determineCheckoutBranchName()
271297

272298
return self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits)
273299
}

pkg/gui/types/common.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ type Model struct {
210210
RemoteBranches []*models.RemoteBranch
211211
Tags []*models.Tag
212212

213-
// Full ref (e.g. "refs/heads/mybranch") of the branch that is currently
214-
// being rebased, or empty string when we're not in a rebase
215-
BranchBeingRebased string
213+
// Name of the currently checked out branch. This will be set even when
214+
// we're on a detached head because we're rebasing or bisecting.
215+
CheckedOutBranch string
216216

217217
// for displaying suggestions while typing in a file name
218218
FilesTrie *patricia.Trie

0 commit comments

Comments
 (0)