resolve the default remote branch dynamically
Rather than hardcode or fall over between branches, look up the
default the remote repo is using, and go with that locally too.
BUG=chromium:1126855, b:173131586
TEST=`./run_tests.sh` passes
Change-Id: I2b6b4aeb6ea404e68d32673c807187c8061d9f16
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/infra/go/+/2693059
Reviewed-by: Julio Hurtado <juahurta@google.com>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/internal/branch/common_test.go b/internal/branch/common_test.go
index 30e4f63..b4eef79 100644
--- a/internal/branch/common_test.go
+++ b/internal/branch/common_test.go
@@ -43,39 +43,12 @@
},
{
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"},
+ ExpectedCmd: []string{"git", "ls-remote", "-q", "--symref", "--exit-code", "origin", "HEAD"},
+ Stdout: "ref: refs/heads/mamama\tHEAD\n5f6803b100bb3cd0f534e96e88c91373e8ed1c44\tHEAD\n",
},
{
ExpectedDir: "",
- ExpectedCmd: []string{"git", "remote", "add", "origin", "localhost"},
- },
- {
- ExpectedDir: "",
- ExpectedCmd: []string{"git", "fetch", "origin"},
- },
- {
- ExpectedDir: "",
- ExpectedCmd: []string{"git", "checkout", "master"},
+ ExpectedCmd: []string{"git", "checkout", "mamama"},
},
},
}