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.go b/internal/branch/common.go
index 0ec6c88..fda68f6 100644
--- a/internal/branch/common.go
+++ b/internal/branch/common.go
@@ -100,7 +100,12 @@
if opts != nil && opts.Ref != "" {
checkoutBranch = git.StripRefs(opts.Ref)
}
- if err := git.Checkout(checkoutDir, checkoutBranch); err != nil {
+ // TODO: remove `master` when COIL is completed
+ if err := git.Checkout(checkoutDir, checkoutBranch); err != nil && checkoutBranch == "master" {
+ checkoutBranch = "main"
+ err = git.Checkout(checkoutDir, checkoutBranch)
+ }
+ if err != nil {
return "", fmt.Errorf("failed to checkout %s", checkoutBranch)
}