diff --git a/pkg/commands/git_commands/branch.go b/pkg/commands/git_commands/branch.go index 6333d136e..c5c81e223 100644 --- a/pkg/commands/git_commands/branch.go +++ b/pkg/commands/git_commands/branch.go @@ -102,12 +102,10 @@ func (self *BranchCommands) CurrentBranchInfo() (BranchInfo, error) { }, nil } -// CurrentBranchName get name of current branch +// CurrentBranchName get name of current branch. Returns empty string if HEAD is detached. func (self *BranchCommands) CurrentBranchName() (string, error) { - cmdArgs := NewGitCmd("rev-parse"). - Arg("--abbrev-ref"). - Arg("--verify"). - Arg("HEAD"). + cmdArgs := NewGitCmd("branch"). + Arg("--show-current"). ToArgv() output, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput() diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 0e19149c1..2e0e157e3 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -308,7 +308,7 @@ func (self *RefreshHelper) determineCheckedOutBranchName() string { // In all other cases, get the branch name by asking git what branch is // checked out. Note that if we're on a detached head (for reasons other // than rebasing or bisecting, i.e. it was explicitly checked out), then - // this will return its hash. + // this will return an empty string. if branchName, err := self.c.Git().Branch.CurrentBranchName(); err == nil { return branchName } diff --git a/pkg/integration/tests/commit/do_not_show_branch_marker_for_head_commit.go b/pkg/integration/tests/commit/do_not_show_branch_marker_for_head_commit.go index 70b1cb22e..54b988ef4 100644 --- a/pkg/integration/tests/commit/do_not_show_branch_marker_for_head_commit.go +++ b/pkg/integration/tests/commit/do_not_show_branch_marker_for_head_commit.go @@ -26,7 +26,7 @@ var DoNotShowBranchMarkerForHeadCommit = NewIntegrationTest(NewIntegrationTestAr // Check that the local commits view does show a branch marker for the head commit t.Views().Commits(). Lines( - Contains("CI * three"), // don't want the star here + Contains("CI three"), Contains("CI two"), Contains("CI branch1 one"), )