Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get the CurrentBranch from git instead of parsing text #295

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,29 +110,14 @@ func Log(sha1, sha2 string) (string, error) {
return string(outputs), nil
}

// CurrentBranch returns the currently checked out branch and strips away all
// but the branchname itself.
// CurrentBranch returns the currently checked out branch
func CurrentBranch() (string, error) {
cmd := New("branch")
cmd.Stdout = nil
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error in CI is because you still need this line I'm afraid. Great looking changes tho! Love deleted code!

gBranches, err := cmd.Output()
cmd := New("rev-parse", "--abbrev-ref", "HEAD")
branch, err := cmd.Output()
if err != nil {
return "", err
}
branches := strings.Split(string(gBranches), "\n")
var branch string
for _, b := range branches {
if strings.HasPrefix(b, "* ") {
branch = b
break
}
}
if branch == "" {
return "", errors.New("current branch could not be determined")
}
branch = strings.TrimPrefix(branch, "* ")
branch = strings.TrimSpace(branch)
return branch, nil
return string(branch), nil
}

// PathWithNameSpace returns the owner/repository for the current repo
Expand Down