changeset 220:06eb60f9a026

push: Do not attempt to push empty revisions.
author Augie Fackler <durin42@gmail.com>
date Sat, 28 Mar 2009 17:50:00 -0500
parents 794f473b9b49
children ced45b753ba7
files push_cmd.py tests/test_push_command.py
diffstat 2 files changed, 43 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/push_cmd.py
+++ b/push_cmd.py
@@ -11,6 +11,15 @@ import fetch_command
 import utility_commands
 
 
+class BaseException(Exception):
+    pass
+
+
+class NoFilesException(BaseException):
+    """Exception raised when you try and commit without files.
+    """
+
+
 def push_revisions_to_subversion(ui, repo, hg_repo_path, svn_url,
                                  stupid=False, **opts):
     """push revisions starting at a specified head back to Subversion.
@@ -50,7 +59,12 @@ def push_revisions_to_subversion(ui, rep
                                   and c.node() in svn_commit_hashes]
         # 2. Commit oldest revision that needs to be pushed
         base_revision = svn_commit_hashes[base_n][0]
-        commit_from_rev(ui, repo, old_ctx, hge, svn_url, base_revision)
+        try:
+            commit_from_rev(ui, repo, old_ctx, hge, svn_url, base_revision)
+        except NoFilesException:
+            ui.warn("Could not push revision %s because it had no changes in svn.\n" %
+                     old_ctx)
+            return 1
         # 3. Fetch revisions from svn
         r = fetch_command.fetch_revisions(ui, svn_url, hg_repo_path,
                                           stupid=stupid)
@@ -268,6 +282,8 @@ def commit_from_rev(ui, repo, rev_ctx, h
     addeddirs = [svnpath(d) for d in addeddirs]
     deleteddirs = [svnpath(d) for d in deleteddirs]
     new_target_files += addeddirs + deleteddirs + changeddirs
+    if not new_target_files:
+        raise NoFilesException()
     try:
         svn.commit(new_target_files, rev_ctx.description(), file_data,
                    base_revision, set(addeddirs), set(deleteddirs),
--- a/tests/test_push_command.py
+++ b/tests/test_push_command.py
@@ -87,6 +87,32 @@ class PushTests(test_util.TestBase):
                                          self.repo_path,
                                          self.wc_path)
 
+    def test_cant_push_empty_ctx(self):
+        repo = self.repo
+        def file_callback(repo, memctx, path):
+            if path == 'adding_file':
+                return context.memfilectx(path=path,
+                                          data='foo',
+                                          islink=False,
+                                          isexec=False,
+                                          copied=False)
+            raise IOError()
+        ctx = context.memctx(repo,
+                             (repo['default'].node(), node.nullid),
+                             'automated test',
+                             [],
+                             file_callback,
+                             'an_author',
+                             '2008-10-07 20:59:48 -0500',
+                             {'branch': 'default',})
+        new_hash = repo.commitctx(ctx)
+        hg.update(repo, repo['tip'].node())
+        old_tip = repo['tip'].node()
+        self.pushrevisions()
+        tip = self.repo['tip']
+        self.assertEqual(tip.node(), old_tip)
+
+
     def test_push_to_default(self, commit=True):
         repo = self.repo
         old_tip = repo['tip'].node()