[tools][perfmon]: Minor improvements

* Ignore changes on non-main branches
* Increase the timeout for git cloning the repo
* Improve the error message on git error

Change-Id: I22af2b8042c14c3c413f52d65dc5b89b7f5c3f11
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132820
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/tools/src/cmd/perfmon/main.go b/tools/src/cmd/perfmon/main.go
index 530bbd9..bcaf8e9 100644
--- a/tools/src/cmd/perfmon/main.go
+++ b/tools/src/cmd/perfmon/main.go
@@ -863,6 +863,11 @@
 		}
 
 		canBenchmark := func() bool {
+			// Don't benchmark changes on non-main branches
+			if change.Branch != "main" {
+				return false
+			}
+
 			// Is the change from a Googler, reviewed by a Googler or is from a allow-listed external developer?
 			if !(strings.HasSuffix(current.Commit.Committer.Email, "@google.com") ||
 				strings.HasSuffix(change.Labels["Code-Review"].Approved.Email, "@google.com") ||
@@ -1045,6 +1050,7 @@
 		repo, err = g.Clone(filepath, cfg.URL, &git.CloneOptions{
 			Branch:      cfg.Branch,
 			Credentials: cfg.Credentials,
+			Timeout:     time.Minute * 30,
 		})
 	}
 	if err != nil {
diff --git a/tools/src/git/git.go b/tools/src/git/git.go
index 9af245f..f949cf6 100644
--- a/tools/src/git/git.go
+++ b/tools/src/git/git.go
@@ -472,8 +472,11 @@
 		fmt.Println(string(out))
 	}
 	if err != nil {
-		return string(out), fmt.Errorf("%v> %v %v failed:\n  %w\n%v",
-			dir, g.exe, strings.Join(args, " "), err, string(out))
+		msg := fmt.Sprintf("%v> %v %v failed:", dir, g.exe, strings.Join(args, " "))
+		if err := ctx.Err(); err != nil {
+			msg += "\n" + err.Error()
+		}
+		return string(out), fmt.Errorf("%s\n  %w\n%v", msg, err, string(out))
 	}
 	return strings.TrimSpace(string(out)), nil
 }