devtools/depotview: fix stale branches, clone bug

Change-Id: Ia2c680d511e3a8b632414caae3058db20d8231ba
diff --git a/devtools/depotview/service/service.go b/devtools/depotview/service/service.go
index fad2029..be5e743 100644
--- a/devtools/depotview/service/service.go
+++ b/devtools/depotview/service/service.go
@@ -46,8 +46,10 @@
 
 func (s *Service) ensureRepo(ctx context.Context) error {
 	// Clone repository if necessary.
+	// Use background context - we don't want this to get canceled.
 	if s.repo == nil {
-		repo, err := git.CloneContext(ctx, s.storer, nil, &git.CloneOptions{
+		glog.Infof("Cloning %q...", s.remote)
+		repo, err := git.CloneContext(context.Background(), s.storer, nil, &git.CloneOptions{
 			URL: s.remote,
 		})
 		if err != nil {
@@ -55,14 +57,19 @@
 			return status.Error(codes.Unavailable, "could not clone repository")
 		}
 		s.repo = repo
+		glog.Infof("Clone done.")
+	}
+
+	// We could've gotten canceled by now.
+	if err := ctx.Err(); err != nil {
+		return err
 	}
 
 	// Fetch if necessary.
 	if time.Since(s.lastFetch) > 10*time.Second {
-		glog.Infof("Fetching...")
 		err := s.repo.FetchContext(ctx, &git.FetchOptions{
 			RefSpecs: []config.RefSpec{
-				config.RefSpec("+refs/heads/*:refs/remotes/origin/*"),
+				config.RefSpec("+refs/heads/*:refs/heads/*"),
 				config.RefSpec("+refs/changes/*:refs/changes/*"),
 			},
 			Force: true,