Add ref parameter when creating a try job

This fixes git cl try when revision is passed.

R=ehmaldonado@chromium.org

Bug: 1138785
Change-Id: Id5a067114426ed55409b1f200abf4d5a38fdbaa5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2691312
Auto-Submit: Josip Sokcevic <sokcevic@google.com>
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
diff --git a/git_cl.py b/git_cl.py
index 6e7e148..c02d23e 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -392,10 +392,12 @@
     })
 
     if options.ensure_value('revision', None):
+      remote, remote_branch = changelist.GetRemoteBranch()
       requests[-1]['scheduleBuild']['gitilesCommit'] = {
           'host': gerrit_changes[0]['host'],
           'project': gerrit_changes[0]['project'],
-          'id': options.revision
+          'id': options.revision,
+          'ref': GetTargetRef(remote, remote_branch, None)
        }
 
   return requests
diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py
index 388bfa0..6100f6e 100755
--- a/tests/git_cl_test.py
+++ b/tests/git_cl_test.py
@@ -86,6 +86,9 @@
     del patchset
     return self._gerrit_change
 
+  def GetRemoteBranch(self):
+    return ('origin', 'refs/remotes/origin/main')
+
 
 class GitMocks(object):
   def __init__(self, config=None, branchref=None):
@@ -3509,6 +3512,8 @@
   @mock.patch('git_cl._call_buildbucket')
   def testScheduleOnBuildbucketWithRevision(self, mockCallBuildbucket):
     mockCallBuildbucket.return_value = {}
+    mock.patch('git_cl.Changelist.GetRemoteBranch',
+               return_value=('origin', 'refs/remotes/origin/main')).start()
 
     self.assertEqual(0, git_cl.main([
         'try', '-B', 'luci.chromium.try', '-b', 'win', '-b', 'linux',
@@ -3548,6 +3553,7 @@
                     "host": "chromium-review.googlesource.com",
                     "project": "depot_tools",
                     "id": "beeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeef",
+                    "ref": "refs/heads/main",
                 }
             },
         },
@@ -3578,6 +3584,7 @@
                     "host": "chromium-review.googlesource.com",
                     "project": "depot_tools",
                     "id": "beeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeef",
+                    "ref": "refs/heads/main",
                 }
             },
         }],
@@ -3801,7 +3808,8 @@
         requests[0]['scheduleBuild']['gitilesCommit'], {
             'host': 'chromium-review.googlesource.com',
             'id': 'ba5eba11',
-            'project': 'depot_tools'
+            'project': 'depot_tools',
+            'ref': 'refs/heads/main',
         })
 
   def testMakeRequestsHelperRetryFailedSet(self):