Skip to content

Commit

Permalink
Merge pull request #27 from screwdriver-cd/fixbranch
Browse files Browse the repository at this point in the history
Adding parsing of the branch from SCMUrl
  • Loading branch information
stjohnjohnson authored Aug 5, 2016
2 parents 47a4cce + 4219f1a commit 41b3cf6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 11 additions & 1 deletion git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,28 @@ import (
"fmt"
"os"
"os/exec"
"strings"
)

var execCommand = exec.Command

// Clone clones a git repo into a destination directory
func Clone(repo, destination string) error {
func Clone(scmURL, destination string) error {
parts := strings.Split(scmURL, "#")
if len(parts) < 2 {
return fmt.Errorf("expected #branchname in SCM URL: %v", scmURL)
}

repo := parts[0]
cmd := execCommand("git", "clone", repo, destination)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

err := cmd.Start()
if err != nil {
return fmt.Errorf("starting git clone command: %v", err)
}

err = cmd.Wait()
if err != nil {
return fmt.Errorf("cloning git repo: %v", err)
Expand Down
7 changes: 4 additions & 3 deletions git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ func fakeExecCommand(command string, args ...string) *exec.Cmd {
return cmd
}

func TestCheckout(t *testing.T) {
wantRepo := "testrepo"
func TestClone(t *testing.T) {
wantRepo := "git@github.com:screwdriver-cd/launcher"
scmURL := "git@github.com:screwdriver-cd/launcher#master"
wantDest := "testdest"
execCommand = getFakeExecCommand(func(cmd string, args ...string) {
want := []string{
Expand All @@ -40,7 +41,7 @@ func TestCheckout(t *testing.T) {
}
})

err := Clone(wantRepo, wantDest)
err := Clone(scmURL, wantDest)
if err != nil {
t.Errorf("Unexpected error from git clone: %v", err)
}
Expand Down

0 comments on commit 41b3cf6

Please sign in to comment.