Skip to content

Commit 8caa718

Browse files
authored
Strip leading - from local branch names (#52)
1 parent fd5797b commit 8caa718

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

pkg/avancement/service_manager_test.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,24 @@ func TestGenerateBranchForLocalSource(t *testing.T) {
211211
func generateBranchWithSuccess(t *testing.T, repo git.Repo) {
212212
branch := generateBranch(repo)
213213
nameRegEx := "^([0-9A-Za-z]+)-([0-9a-z]{7})-([0-9A-Za-z]{5})$"
214-
_, err := regexp.Match(nameRegEx, []byte(branch))
214+
matched, err := regexp.Match(nameRegEx, []byte(branch))
215215
if err != nil {
216-
t.Fatalf("failed to generate a branch name matching pattern %s", nameRegEx)
216+
t.Fatalf("Regexp err %s in generateBranchWithSuccess matching pattern %s to %s", err, nameRegEx, branch)
217+
}
218+
if !matched {
219+
t.Fatalf("generated name `%s` failed to match pattern %s", branch, nameRegEx)
217220
}
218221
}
219222

220223
func generateBranchForLocalWithSuccess(t *testing.T, source git.Source) {
221224
branch := generateBranchForLocalSource(source)
222225
nameRegEx := "^path-to-topLevel-local-dir-([0-9A-Za-z]{5})$"
223-
_, err := regexp.Match(nameRegEx, []byte(branch))
226+
matched, err := regexp.Match(nameRegEx, []byte(branch))
224227
if err != nil {
225-
t.Fatalf("generated name `%s` for local case %s failed to matching pattern %s", nameRegEx, source.GetName(), nameRegEx)
228+
t.Fatalf("Regexp err %s in generateBranchForLocalWithSuccess matching pattern %s to %s", err, nameRegEx, branch)
229+
}
230+
if !matched {
231+
t.Fatalf("generated name `%s` for local case %s failed to matching pattern %s", branch, source.GetName(), nameRegEx)
226232
}
227233
}
228234

@@ -263,7 +269,10 @@ func (s *mockSource) Walk(_ string, cb func(string, string) error) error {
263269
}
264270

265271
func (s *mockSource) GetName() string {
266-
return "mock-source-name"
272+
path := filepath.ToSlash(s.localPath)
273+
path = strings.TrimLeft(path, "/")
274+
name := strings.ReplaceAll(path, "/", "-")
275+
return name
267276
}
268277

269278
func (s *mockSource) AddFiles(name string) {

pkg/git/mock/mock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (m *Repository) GetName() string {
6060
}
6161

6262
func (m *Repository) GetCommitID() string {
63-
m.commitID = "fakeCommitString"
63+
m.commitID = "a1b2c3d"
6464
return m.commitID
6565
}
6666

pkg/local/local.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func (l *Local) Walk(_ string, cb func(prefix, name string) error) error {
5858
// GetName - we're using a directory that may not be a git repo, all we know is our path
5959
func (l *Local) GetName() string {
6060
path := filepath.ToSlash(l.LocalPath)
61+
path = strings.TrimLeft(path, "/")
6162
name := strings.ReplaceAll(path, "/", "-")
6263
return name
6364
}

pkg/local/local_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (s *mockSource) Walk(_ string, cb func(string, string) error) error {
6464
}
6565

6666
func (s *mockSource) GetName() string {
67-
return "AlwaysTheSameName"
67+
return "/workspace/path/to/dir"
6868
}
6969

7070
func (s *mockSource) addFile(name string) {

0 commit comments

Comments
 (0)