Skip to content

Commit

Permalink
Don't panic on unmatched default
Browse files Browse the repository at this point in the history
  • Loading branch information
robertgzr committed Apr 28, 2017
1 parent 51d41ea commit ec29032
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions porcelain.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ func parseBranchinfo(s string) {

reCatch := regexp.MustCompile("\\s([a-zA-Z0-9-_\\.]+)\\s(?:\\W[\\w\\s]*\\W)")
matchDefault = reCatch.FindStringSubmatch(s)
Git.commit = matchDefault[1]
if matchDefault != nil {
Git.commit = matchDefault[1]
}

} else {

Expand Down Expand Up @@ -298,9 +300,9 @@ func execRevParse() (string, error) {
out, err := cmd.Output()
if err != nil {
// if strings.Contains(err.Error(), "128") {
// return "initial"
// return "initial"
// } else {
// panic(err)
// panic(err)
// }
return "initial", err
// TODO: would be nice to be able to differentiate between not in git and before
Expand Down
4 changes: 4 additions & 0 deletions porcelain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var (
"## master...origin/master [ahead 1, behind 99]",
"## Initial commit on master",
"## HEAD (no branch)",
"## user/feature...origin/user/feature",
"## user/feature...origin/user/feature [ahead 99, behind 5]",
}
branchInfoExpected = []gitinfo{
gitinfo{branch: "new2", commit: "", remote: "", trackedBranch: "", ahead: 0, behind: 0},
Expand All @@ -24,6 +26,8 @@ var (
gitinfo{branch: "master", commit: "", remote: "origin", trackedBranch: "origin/master", ahead: 1, behind: 99},
gitinfo{branch: "master", commit: "", remote: "", trackedBranch: "", ahead: 0, behind: 0},
gitinfo{branch: "", commit: "HEAD", remote: "", trackedBranch: "", ahead: 0, behind: 0},
gitinfo{branch: "user/feature", commit: "", remote: "origin", trackedBranch: "user/feature", ahead: 0, behind: 0},
gitinfo{branch: "user/feature", commit: "", remote: "origin", trackedBranch: "user/feature", ahead: 99, behind: 5},
}
)

Expand Down

0 comments on commit ec29032

Please sign in to comment.