Skip to content

Commit

Permalink
Use regular 'git branch' call instead of using --show-current
Browse files Browse the repository at this point in the history
Older versions of git don't support --show-current flag.

commit-id:e54c8b99
  • Loading branch information
ejoffe committed Jul 19, 2021
1 parent cf322ce commit be7037f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions github/githubclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"regexp"
"strings"

"github.com/ejoffe/spr/config"
"github.com/ejoffe/spr/git"
Expand Down Expand Up @@ -87,9 +88,7 @@ func (c *client) GetInfo(ctx context.Context, gitcmd git.GitInterface) *github.G
err := c.api.Query(ctx, &query, variables)
check(err)

var branchname string
err = gitcmd.Git("branch --show-current", &branchname)
check(err)
branchname := getLocalBranchName(gitcmd)

var requests []*github.PullRequest
for _, node := range query.Viewer.PullRequests.Nodes {
Expand Down Expand Up @@ -325,6 +324,19 @@ func (c *client) ClosePullRequest(ctx context.Context, pr *github.PullRequest) {
}
}

func getLocalBranchName(gitcmd git.GitInterface) string {
var output string
err := gitcmd.Git("branch", &output)
check(err)
lines := strings.Split(output, "\n")
for _, line := range lines {
if strings.HasPrefix(line, "* ") {
return line[2:]
}
}
panic("cannot determine local git branch name")
}

func branchNameFromCommit(info *github.GitHubInfo, commit git.Commit) string {
return "pr/" + info.UserName + "/" + info.LocalBranch + "/" + commit.CommitID
}
Expand Down

0 comments on commit be7037f

Please sign in to comment.