Added CreateRemoteRef to repo_harness (and accompanying git package updates)

Added CreateRemoteRef to the repo_harness package as discussed in
crrev.com/c/1706930. Naturally, this required adding a few methods to
the git package.

TEST=run_tests.sh
BUG=chromium:980346

Change-Id: Ida29844381e3212fbe9b247af106c4dedffa7ed8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/infra/go/+/1710949
Commit-Queue: Jack Neus <jackneus@google.com>
Tested-by: Jack Neus <jackneus@google.com>
Reviewed-by: Evan Hernandez <evanhernandez@chromium.org>
diff --git a/internal/git/git.go b/internal/git/git.go
index f1ceef3..7395ca8 100644
--- a/internal/git/git.go
+++ b/internal/git/git.go
@@ -193,11 +193,11 @@
 	if err != nil && !strings.Contains(err.Error(), "nothing to commit") {
 		return err
 	}
-	return Push(gitRepo, localRef, dryRun, pushTo)
+	return PushRef(gitRepo, localRef, dryRun, pushTo)
 }
 
-// Push pushes the specified local ref to the specified remote ref.
-func Push(gitRepo, localRef string, dryRun bool, pushTo RemoteRef) error {
+// PushRef pushes the specified local ref to the specified remote ref.
+func PushRef(gitRepo, localRef string, dryRun bool, pushTo RemoteRef) error {
 	ref := fmt.Sprintf("%s:%s", localRef, pushTo.Ref)
 	cmd := []string{"push", pushTo.Remote, ref}
 	if dryRun {
@@ -221,7 +221,9 @@
 func AddRemote(gitRepo, remote, remoteLocation string) error {
 	output, err := RunGit(gitRepo, []string{"remote", "add", remote, remoteLocation})
 	if err != nil {
-		fmt.Printf("remote error: %s\n", output.Stderr)
+		if strings.Contains(output.Stderr, "already exists") {
+			return fmt.Errorf("remote already exists")
+		}
 	}
 	return err
 }