hgext: get push-to-try to support try_task_config.json method of scheduling (bug 1384563) draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Wed, 26 Jul 2017 09:19:07 -0400
changeset 11401 fe0fc1964ba55be610c5aa8aee88a0c5d9fa5ca8
parent 11341 72b7800ab16fe777cfbb6e4d5ce47f8d74f4fe80
push id1743
push userahalberstadt@mozilla.com
push dateFri, 28 Jul 2017 18:21:41 +0000
bugs1384563
hgext: get push-to-try to support try_task_config.json method of scheduling (bug 1384563) MozReview-Commit-ID: 3q9VZv1k8Xk
hgext/push-to-try/__init__.py
hgext/push-to-try/tests/test-file-delete.t
hgext/push-to-try/tests/test-preserve-flags.t
hgext/push-to-try/tests/test-push-to-try.t
hgext/push-to-try/tests/test-try-config.t
--- a/hgext/push-to-try/__init__.py
+++ b/hgext/push-to-try/__init__.py
@@ -19,37 +19,40 @@ testedwith = '3.8 3.9 4.0 4.1 4.2'
 @command('push-to-try', [
     ('m', 'message', '', 'commit message to use', 'MESSAGE'),
     ('s', 'server', 'ssh://hg.mozilla.org/try', 'push destination', 'URL'),
 ], '-m MESSAGE -s URL')
 def push_to_try(ui, repo, server, message=None):
 
     nodate = ui.configbool('push-to-try', 'nodate')
 
-    if not message or 'try:' not in message:
-        ui.status("STOP! A commit message with try syntax is required.\n")
+    if not message:
+        ui.status("STOP! A commit message is required.\n")
         return
 
     cctx = context.workingctx(repo)
-    status = repo.status()
+    if 'try_task_config.json' not in cctx and 'try:' not in message:
+        ui.status("STOP! Either try_task_config.json must be added or the commit "
+                  "message must contain try syntax.\n")
+        return
 
+    # Invent a temporary commit with our message.
+    ui.status("Creating temporary commit for remote...\n")
+    status = repo.status()
     if status.modified + status.added + status.removed:
-        ui.status('The following will be pushed to %s:\n' % server)
         # TODO: Achieve this by re-using the status call above to avoid the
         # cost of running it twice.
         commands.status(ui, repo)
 
     preserve_ctx = preservefilectx(cctx)
     def mk_memfilectx(repo, memctx, path):
         if path not in status.removed:
             return preserve_ctx(repo, memctx, path)
         return None
 
-    # Invent a temporary commit with our message.
-    ui.status("Creating temporary commit for remote...\n")
     mctx = context.memctx(repo,
                           repo.dirstate.parents(),
                           message,
                           cctx.files(),
                           mk_memfilectx,
                           date="0 0" if nodate else None)
 
     # These messages are expected when we abort our transaction, but aren't
--- a/hgext/push-to-try/tests/test-file-delete.t
+++ b/hgext/push-to-try/tests/test-file-delete.t
@@ -23,20 +23,19 @@ Test pushing with outstanding changes th
   $ hg rm file1.txt
   $ echo line3 > file2.txt
 
   $ hg status
   M file2.txt
   R file1.txt
 
   $ hg push-to-try -m 'try: syntax' -s ../remote
-  The following will be pushed to ../remote:
+  Creating temporary commit for remote...
   M file2.txt
   R file1.txt
-  Creating temporary commit for remote...
   pushing to ../remote
   searching for changes
   adding changesets
   adding manifests
   adding file changes
   added 2 changesets with 3 changes to 2 files
   push complete
   temporary commit removed, repository restored
--- a/hgext/push-to-try/tests/test-preserve-flags.t
+++ b/hgext/push-to-try/tests/test-preserve-flags.t
@@ -23,19 +23,18 @@ Test pushing an outstanding change prese
   $ hg add file2.txt
   $ hg diff
   diff -r 153ffc71bd76 file2.txt
   --- /dev/null
   +++ b/file2.txt
   @@ -0,0 +1,1 @@
   +line1
   $ hg push-to-try -m 'try: syntax' -s ../remote
-  The following will be pushed to ../remote:
+  Creating temporary commit for remote...
   A file2.txt
-  Creating temporary commit for remote...
   pushing to ../remote
   searching for changes
   adding changesets
   adding manifests
   adding file changes
   added 2 changesets with 2 changes to 2 files
   push complete
   temporary commit removed, repository restored
--- a/hgext/push-to-try/tests/test-push-to-try.t
+++ b/hgext/push-to-try/tests/test-push-to-try.t
@@ -23,19 +23,18 @@ state.
   $ hg add file2.txt
   $ hg diff
   diff -r 153ffc71bd76 file2.txt
   --- /dev/null
   +++ b/file2.txt
   @@ -0,0 +1,1 @@
   +line1
   $ hg push-to-try -m 'try: syntax' -s ../remote
-  The following will be pushed to ../remote:
+  Creating temporary commit for remote...
   A file2.txt
-  Creating temporary commit for remote...
   pushing to ../remote
   searching for changes
   adding changesets
   adding manifests
   adding file changes
   added 2 changesets with 2 changes to 2 files
   push complete
   temporary commit removed, repository restored
new file mode 100644
--- /dev/null
+++ b/hgext/push-to-try/tests/test-try-config.t
@@ -0,0 +1,67 @@
+Test pushing with a try_task_config.json works
+
+  $ cat >> $HGRCPATH << EOF
+  > [extensions]
+  > push-to-try = $TESTDIR/hgext/push-to-try
+  > [push-to-try]
+  > nodate = true
+  > [defaults]
+  > diff = --nodate
+  > EOF
+
+  $ hg init remote
+
+  $ hg clone remote local
+  updating to branch default
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ cd local
+  $ echo line1 > file1.txt
+  $ echo line1 > file2.txt
+  $ hg add file1.txt
+  $ hg commit -m "file1.txt added"
+
+  $ echo line1 > try_task_config.json
+  $ hg add try_task_config.json
+  $ hg push-to-try -m "Add try_task_config.json" -s ../remote
+  Creating temporary commit for remote...
+  A try_task_config.json
+  ? file2.txt
+  pushing to ../remote
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 2 changesets with 2 changes to 2 files
+  push complete
+  temporary commit removed, repository restored
+  $ hg verify
+  checking changesets
+  checking manifests
+  crosschecking files in changesets and manifests
+  checking files
+  1 files, 1 changesets, 1 total revisions
+
+Test try commit made it to our remote
+
+  $ cd ../remote
+  $ hg log
+  changeset:   1:d406ccbd602f
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     Add try_task_config.json
+  
+  changeset:   0:153ffc71bd76
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     file1.txt added
+  
+  $ hg up -r 1
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg diff -r 0
+  diff -r 153ffc71bd76 try_task_config.json
+  --- /dev/null
+  +++ b/try_task_config.json
+  @@ -0,0 +1,1 @@
+  +line1