Create branches for projects with revision set

It turns out Initialize() was somewhat incomplete -- if a project has a
revision set (e.g. refs/heads/foo), then a branch needs to be created
for that revision.

BUG=chromium:980346
TEST=run_tests.sh

Change-Id: Ia5ac4d2c1b6bab5aa864ecf31b496bbe3852421a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/infra/go/+/1712453
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 3fb7179..f1ceef3 100644
--- a/internal/git/git.go
+++ b/internal/git/git.go
@@ -104,7 +104,7 @@
 	return strings.TrimSpace(output.Stdout), err
 }
 
-// StipRefsHead removes leading 'refs/heads/' from a ref name.
+// StripRefsHead removes leading 'refs/heads/' from a ref name.
 func StripRefsHead(ref string) string {
 	return strings.TrimPrefix(ref, "refs/heads/")
 }
@@ -177,6 +177,14 @@
 	return nil
 }
 
+// CommitEmpty makes an empty commit (assuming nothing is staged).
+func CommitEmpty(gitRepo, commitMsg string) error {
+	if output, err := RunGit(gitRepo, []string{"commit", "-m", commitMsg, "--allow-empty"}); err != nil {
+		return fmt.Errorf(output.Stderr)
+	}
+	return nil
+}
+
 // PushGitChanges stages and commits any local changes before pushing the commit
 // to the specified remote ref.
 func PushChanges(gitRepo, localRef, commitMsg string, dryRun bool, pushTo RemoteRef) error {
@@ -185,12 +193,17 @@
 	if err != nil && !strings.Contains(err.Error(), "nothing to commit") {
 		return err
 	}
+	return Push(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 {
 	ref := fmt.Sprintf("%s:%s", localRef, pushTo.Ref)
 	cmd := []string{"push", pushTo.Remote, ref}
 	if dryRun {
 		cmd = append(cmd, "--dry-run")
 	}
-	_, err = RunGit(gitRepo, cmd)
+	_, err := RunGit(gitRepo, cmd)
 	return err
 }