changeset 356:62f90781eb10

push: don't refuse to push if it looks like we haven't pulled all changes. We can't rely on the most-recent change number matching our most-recent change number because there can be changes in svn that produce no corresponding hg changeset.
author Augie Fackler <durin42@gmail.com>
date Wed, 27 May 2009 21:40:58 -0500
parents 256863a65141
children d19843ac13c9
files hgsubversion/wrappers.py tests/test_push_command.py
diffstat 2 files changed, 40 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/wrappers.py
+++ b/hgsubversion/wrappers.py
@@ -94,20 +94,6 @@ def push(repo, dest, force, revs):
     svn = svnwrap.SubversionRepo(svnurl, user, passwd)
     hge = hg_delta_editor.HgChangeReceiver(repo=repo, uuid=svn.uuid)
 
-    # Check if we are up-to-date with the Subversion repository.
-    if hge.last_known_revision() != svn.last_changed_rev:
-        # Messages are based on localrepository.push() in localrepo.py:1559. 
-        # TODO: Ideally, we would behave exactly like other repositories:
-        #  - push everything by default
-        #  - handle additional heads in the same way
-        #  - allow pushing single revisions, branches, tags or heads using
-        #    the -r/--rev flag.
-        if force:
-            ui.warn("note: unsynced remote changes!\n")
-        else:
-            ui.warn("abort: unsynced remote changes!\n")
-            return None, 0
-
     # Strategy:
     # 1. Find all outgoing commits from this head
     if len(repo.parents()) != 1:
@@ -235,7 +221,7 @@ def pull(repo, source, heads=[], force=F
     try:
         # start converting revisions
         for r in svn.revisions(start=start, stop=stopat_rev):
-            if (r.author is None and 
+            if (r.author is None and
                 r.message == 'This is an empty revision for padding.'):
                 continue
             hg_editor.update_branch_tag_map_for_rev(r)
--- a/tests/test_push_command.py
+++ b/tests/test_push_command.py
@@ -1,6 +1,7 @@
 import atexit
 import os
 import random
+import shutil
 import socket
 import subprocess
 import unittest
@@ -212,7 +213,7 @@ class PushTests(test_util.TestBase):
             pass
         self.assertEqual(tip.branch(), 'default')
 
-    def test_push_to_branch(self):
+    def test_push_to_branch(self, push=True):
         repo = self.repo
         def file_callback(repo, memctx, path):
             if path == 'adding_file':
@@ -231,13 +232,45 @@ class PushTests(test_util.TestBase):
                              '2008-10-07 20:59:48 -0500',
                              {'branch': 'the_branch',})
         new_hash = repo.commitctx(ctx)
-        #commands.update(ui.ui(), self.repo, node='tip')
         hg.update(repo, repo['tip'].node())
+        if push:
+            self.pushrevisions()
+            tip = self.repo['tip']
+            self.assertNotEqual(tip.node(), new_hash)
+            self.assertEqual(tip['adding_file'].data(), 'foo')
+            self.assertEqual(tip.branch(), 'the_branch')
+
+    def push_to_non_tip(self):
+        self.test_push_to_branch(push=False)
+        wc2path = self.wc_path + '_clone'
+        u = self.repo.ui
+        hg.clone(self.repo.ui, self.wc_path, wc2path, update=False)
         self.pushrevisions()
-        tip = self.repo['tip']
-        self.assertNotEqual(tip.node(), new_hash)
-        self.assertEqual(tip['adding_file'].data(), 'foo')
-        self.assertEqual(tip.branch(), 'the_branch')
+        oldf = open(os.path.join(self.wc_path, '.hg', 'hgrc'))
+        hgrc = oldf.read()
+        oldf.close()
+        shutil.rmtree(self.wc_path)
+        hg.clone(u, wc2path, self.wc_path, update=False)
+        oldf = open(os.path.join(self.wc_path, '.hg', 'hgrc'), 'w')
+        oldf.write(hgrc)
+        oldf.close()
+
+        # do a commit here
+        self.commitchanges([('foobaz', 'foobaz', 'This file is added on default.', ),
+                            ],
+                           parent='default',
+                           message='commit to default')
+        from hgsubversion import svncommands
+        svncommands.rebuildmeta(u,
+                                self.repo,
+                                os.path.dirname(self.repo.path),
+                                args=[test_util.fileurl(self.repo_path)])
+
+
+        hg.update(self.repo, self.repo['tip'].node())
+        oldnode = self.repo['tip'].hex()
+        self.pushrevisions(expected_extra_back=1)
+        self.assertNotEqual(oldnode, self.repo['tip'].hex(), 'Revision was not pushed.')
 
     def test_delete_file(self):
         repo = self.repo