AppRunner: Clone specific branch instead of always running master

Change-Id: I262d232f5fa1648474eb8bb55ce13f986507b0d4
diff --git a/apps/app-runner/main.go b/apps/app-runner/main.go
index 3d1e397..9296749 100644
--- a/apps/app-runner/main.go
+++ b/apps/app-runner/main.go
@@ -12,6 +12,7 @@
 
 	"github.com/go-git/go-billy/v5/osfs"
 	"github.com/go-git/go-git/v5"
+	"github.com/go-git/go-git/v5/plumbing"
 	gitssh "github.com/go-git/go-git/v5/plumbing/transport/ssh"
 	"github.com/go-git/go-git/v5/storage/memory"
 )
@@ -19,6 +20,7 @@
 var port = flag.Int("port", 3000, "Port to listen on")
 var appId = flag.String("app-id", "", "Application ID")
 var repoAddr = flag.String("repo-addr", "", "Git repository address")
+var branch = flag.String("branch", "", "Name of the branch to process")
 var sshKey = flag.String("ssh-key", "", "Private SSH key to access Git repository")
 var appDir = flag.String("app-dir", "", "Path to store application repository locally")
 var runCfg = flag.String("run-cfg", "", "Run configuration")
@@ -30,7 +32,8 @@
 	Env  []string `json:"env"`
 }
 
-func CloneRepository(addr string, signer ssh.Signer, path string) error {
+func CloneRepositoryBranch(addr, branch string, signer ssh.Signer, path string) error {
+	ref := fmt.Sprintf("refs/heads/%s", branch)
 	c, err := git.Clone(memory.NewStorage(), osfs.New(path, osfs.WithBoundOS()), &git.CloneOptions{
 		URL: addr,
 		Auth: &gitssh.PublicKeys{
@@ -45,7 +48,7 @@
 			},
 		},
 		RemoteName:      "origin",
-		ReferenceName:   "refs/heads/master",
+		ReferenceName:   plumbing.ReferenceName(ref),
 		SingleBranch:    true,
 		Depth:           1,
 		InsecureSkipTLS: true,
@@ -87,7 +90,7 @@
 	if err != nil {
 		panic(err)
 	}
-	if err := CloneRepository(*repoAddr, signer, *appDir); err != nil {
+	if err := CloneRepositoryBranch(*repoAddr, *branch, signer, *appDir); err != nil {
 		panic(err)
 	}
 	r, err := os.Open(*runCfg)
@@ -99,7 +102,7 @@
 	if err := json.NewDecoder(r).Decode(&cmds); err != nil {
 		panic(err)
 	}
-	s := NewServer(*port, *appId, *repoAddr, signer, *appDir, cmds, self, *managerAddr)
+	s := NewServer(*port, *appId, *repoAddr, *branch, signer, *appDir, cmds, self, *managerAddr)
 	if err := s.Start(); err != nil {
 		log.Fatal(err)
 	}