Skip to content

Commit c8d0d97

Browse files
author
Tobias Meinhardt
committed
Fix get current branch
1 parent 9fb14d1 commit c8d0d97

File tree

8 files changed

+23
-16
lines changed

8 files changed

+23
-16
lines changed

branch.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ type branch struct {
2525
name string
2626
}
2727

28-
const BRANCH_NAME_PREFIX = "refs/heads/"
28+
const (
29+
BRANCH_NAME_PREFIX = "refs/heads/"
30+
FEATURE_BRANCH_PATTERN = `feature/[^/]+/.*`
31+
FIX_BRANCH_PATTERN = `fix/[^/]+/.*`
32+
HOTFIX_BRANCH_PATTERN = `hotfix/v.*`
33+
RELEASE_BRANCH_PATTERN = `release/v.*`
34+
)
2935

3036
// NewBranch creates a new branch definition
3137
func NewBranch(name string) Branch {
@@ -43,19 +49,19 @@ func BranchFromBranchName(name string) (b Branch, err error) {
4349
Debug(l.Fields{"branch": b}).
4450
Error(err)
4551
}()
46-
matched, err := regexp.Match(`feature/[^/]+/.*`, []byte(name))
52+
matched, err := regexp.Match(FEATURE_BRANCH_PATTERN, []byte(name))
4753
if matched && err == nil {
4854
return FeatureFromBranch(name)
4955
}
50-
matched, err = regexp.Match(`fix/[^/]+/.*`, []byte(name))
56+
matched, err = regexp.Match(FIX_BRANCH_PATTERN, []byte(name))
5157
if matched && err == nil {
5258
return FixFromBranch(name)
5359
}
54-
matched, err = regexp.Match(`hotfix/v.*`, []byte(name))
60+
matched, err = regexp.Match(HOTFIX_BRANCH_PATTERN, []byte(name))
5561
if matched && err == nil {
5662
return HotfixFromBranch(name)
5763
}
58-
matched, err = regexp.Match(`release/v.*`, []byte(name))
64+
matched, err = regexp.Match(RELEASE_BRANCH_PATTERN, []byte(name))
5965
if matched && err == nil {
6066
return ReleaseFromBranch(name)
6167
}

feature.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func FeatureFromBranch(branchName string) (b AuthoredBranch, err error) {
3333
Info(l.Fields{"branch": b}).
3434
Error(err)
3535
}()
36-
matched, err := regexp.Match(`feature/[^/]+/.*`, []byte(branchName))
36+
matched, err := regexp.Match(FEATURE_BRANCH_PATTERN, []byte(branchName))
3737
if !matched || err != nil {
3838
return feature{}, errors.New("no valid feature branch")
3939
}

feature_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ var _ = Describe("Feature", func() {
1414
var branches []AuthoredBranch
1515

1616
BeforeEach(func() {
17-
f1, _ := NewFeature("luke", "falcon")
18-
f2, _ := FeatureFromBranch(BRANCH_NAME_PREFIX + "feature/luke/falcon")
19-
f3, _ := BranchFromBranchName(BRANCH_NAME_PREFIX + "feature/luke/falcon")
20-
f4, _ := BranchFromBranchName("feature/luke/falcon")
21-
branches = []AuthoredBranch{f1, f2, f3, f4}
17+
f1, _ := NewFeature("luke", "falcon-shuttle")
18+
f2, _ := FeatureFromBranch("feature/luke/falcon-shuttle")
19+
f3, _ := FeatureFromBranch(BRANCH_NAME_PREFIX + "feature/luke/falcon-shuttle")
20+
f4, _ := BranchFromBranchName(BRANCH_NAME_PREFIX + "feature/luke/falcon-shuttle")
21+
f5, _ := BranchFromBranchName("feature/luke/falcon-shuttle")
22+
branches = []AuthoredBranch{f1, f2, f3, f4, f5}
2223
})
2324

2425
It("is of type feature branch", func() {

fix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func FixFromBranch(branchName string) (b AuthoredBranch, err error) {
3232
Info(l.Fields{"branch": b}).
3333
Error(err)
3434
}()
35-
matched, err := regexp.Match(`fix/[^/]+/.*`, []byte(branchName))
35+
matched, err := regexp.Match(FIX_BRANCH_PATTERN, []byte(branchName))
3636
if !matched || err != nil {
3737
return fix{}, errors.New("no valid fix branch")
3838
}

git/native_adapter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (a nativeGitAdapter) CurrentBranch() (branch glow.Branch, stdout, stderr st
3737
}
3838
for _, b := range cmdBranchList {
3939
if b.IsCurrentBranch {
40-
branch := glow.NewBranch(b.Name)
40+
branch, err := glow.BranchFromBranchName(b.Name)
4141
return branch, stdout, stderr, err
4242
}
4343
}

hotfix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func HotfixFromBranch(branchName string) (b Branch, err error) {
3636
Info(l.Fields{"branch": b}).
3737
Error(err)
3838
}()
39-
matched, err := regexp.Match(`hotfix/v.*`, []byte(branchName))
39+
matched, err := regexp.Match(HOTFIX_BRANCH_PATTERN, []byte(branchName))
4040
if !matched || err != nil {
4141
return hotfix{}, errors.New("no valid hotfix branch")
4242
}

release.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func ReleaseFromBranch(branchName string) (b Branch, err error) {
3636
Info(l.Fields{"branch": b}).
3737
Error(err)
3838
}()
39-
matched, err := regexp.Match(`release/v.*`, []byte(branchName))
39+
matched, err := regexp.Match(RELEASE_BRANCH_PATTERN, []byte(branchName))
4040
if !matched || err != nil {
4141
return release{}, errors.New("no valid release branch")
4242
}

suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const (
1717
MASTER_BRANCH = "master"
1818
DEVELOP_BRANCH = "develop"
1919
RELEASE_BRANCH = "release/v1.2.3"
20-
FEAUTURE_BRANCH = "feature/luke/falcon"
20+
FEAUTURE_BRANCH = "feature/luke/falcon-shuttle"
2121
HOTFIX_BRANCH = "hotfix/v0.0.1"
2222
FIX_BRANCH = "fix/luke/falcon"
2323
ANOTHER_BRANCH = "another-branch"

0 commit comments

Comments
 (0)