branch_util: allow both master and main branches

As the COIL initiative makes progress, naming will
begin to change from master to main. This change
preemptively will allow for some functionality to
recognize both names. manifest_repo.go will need
wait till the naming is changed as without extra
flags it seems not possible to allow both naming
schemes.

Tests were added for the common.go file to add coverage
for both main and master namings. create.go didn't need
additional coverage as the change made is already covered
by a gitiles mock.

BUG= b:173131586
TEST=run_test.sh; Dry runs

Change-Id: Iaabf4397a0426f1ddc64faa1f1d516326c8899f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/infra/go/+/2536010
Tested-by: Julio Hurtado <juahurta@google.com>
Reviewed-by: Sean Abraham <seanabraham@chromium.org>
Commit-Queue: Julio Hurtado <juahurta@google.com>
diff --git a/internal/branch/common_test.go b/internal/branch/common_test.go
index 6396709..30e4f63 100644
--- a/internal/branch/common_test.go
+++ b/internal/branch/common_test.go
@@ -5,10 +5,11 @@
 package branch
 
 import (
-	"testing"
-
+	"go.chromium.org/chromiumos/infra/go/internal/cmd"
+	"go.chromium.org/chromiumos/infra/go/internal/git"
 	"go.chromium.org/chromiumos/infra/go/internal/repo"
 	"gotest.tools/assert"
+	"testing"
 )
 
 func TestProjectFetchUrl(t *testing.T) {
@@ -24,3 +25,65 @@
 	assert.NilError(t, err)
 	assert.Equal(t, url, "file:///tmp/path/to/remote/foo/bar/project")
 }
+
+func TestGetProjectCheckoutFromUrl(t *testing.T) {
+	git.CommandRunnerImpl = &cmd.FakeCommandRunnerMulti{
+		CommandRunners: []cmd.FakeCommandRunner{
+			{
+				ExpectedDir: "",
+				ExpectedCmd: []string{"git", "init"},
+			},
+			{
+				ExpectedDir: "",
+				ExpectedCmd: []string{"git", "remote", "add", "origin", "localhost"},
+			},
+			{
+				ExpectedDir: "",
+				ExpectedCmd: []string{"git", "fetch", "origin"},
+			},
+			{
+				ExpectedDir: "",
+				ExpectedCmd: []string{"git", "checkout", "master"},
+				FailCommand: true,
+				FailError:   "Failed to checkout master",
+			},
+		},
+	}
+
+	_, err := getProjectCheckoutFromUrl("localhost", nil)
+
+	if err != nil {
+		t.Error("Error: checkout out project reason: ", err.Error())
+		return
+	}
+}
+
+func TestGetProjectCheckoutFromUrl_coilcheck(t *testing.T) {
+	git.CommandRunnerImpl = &cmd.FakeCommandRunnerMulti{
+		CommandRunners: []cmd.FakeCommandRunner{
+			{
+				ExpectedDir: "",
+				ExpectedCmd: []string{"git", "init"},
+			},
+			{
+				ExpectedDir: "",
+				ExpectedCmd: []string{"git", "remote", "add", "origin", "localhost"},
+			},
+			{
+				ExpectedDir: "",
+				ExpectedCmd: []string{"git", "fetch", "origin"},
+			},
+			{
+				ExpectedDir: "",
+				ExpectedCmd: []string{"git", "checkout", "master"},
+			},
+		},
+	}
+
+	_, err := getProjectCheckoutFromUrl("localhost", nil)
+
+	if err != nil {
+		t.Error("Error: checkout out project reason: ", err.Error())
+		return
+	}
+}