git-cl: add --preserve-tryjobs option for upload command.

CQ will soon start canceling tryjobs it triggered on no-longer-latest
patchsets if these tryjobs won't be re-used. New option can be used by
developers who upload new patchsets but actually care for prior
CQ-triggered tryjobs to complete.

This footer is effectively sticky, unless someone removes it by hand later.
We need to have the footer one way or another to tell the CQ what to do
(and provide a visible audit trail).

We may revisit the stickiness later based on accumulated usage data s.t.
the following uploads remove the footer unless the flag is passed.

Bug: 909895
Test: git cl upload --preserve-tryjobs
Change-Id: Ibbc6e917504c31eab8ab85296b3ecafd3add46df
Cq-Do-Not-Cancel-Tryjobs: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1701506
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Commit-Queue: Andrii Shyshkalov <tandrii@chromium.org>
diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py
index 286e14c..84da763 100755
--- a/tests/git_cl_test.py
+++ b/tests/git_cl_test.py
@@ -210,6 +210,34 @@
       'Gnarly-Dude: beans',
     ])
 
+  def test_set_preserve_tryjobs(self):
+    d = git_cl.ChangeDescription('Simple.')
+    d.set_preserve_tryjobs()
+    self.assertEqual(d.description.splitlines(), [
+      'Simple.',
+      '',
+      'Cq-Do-Not-Cancel-Tryjobs: true',
+    ])
+    before = d.description
+    d.set_preserve_tryjobs()
+    self.assertEqual(before, d.description)
+
+    d = git_cl.ChangeDescription('\n'.join([
+      'One is enough',
+      '',
+      'Cq-Do-Not-Cancel-Tryjobs: dups not encouraged, but don\'t hurt',
+      'Change-Id: Ideadbeef',
+    ]))
+    d.set_preserve_tryjobs()
+    self.assertEqual(d.description.splitlines(), [
+      'One is enough',
+      '',
+      'Cq-Do-Not-Cancel-Tryjobs: dups not encouraged, but don\'t hurt',
+      'Change-Id: Ideadbeef',
+      'Cq-Do-Not-Cancel-Tryjobs: true',
+    ])
+
+
   def test_get_bug_line_values(self):
     f = lambda p, bugs: list(git_cl._get_bug_line_values(p, bugs))
     self.assertEqual(f('', ''), [])