# HG changeset patch # User Kapil Bajaj # Date 1358470905 28800 # Node ID 110794582448c483e2c408458fc4fdc0487613ff # Parent 26e9fd21f3bf74697e1faee15a6a0c6be671130d push: avoid failure when push is being called from a newly created subdirectory The failure was occuring during push when a new file is added inside a new subdirectory and push is being called from this subdirectory. This subdirectory disappears when the commit is being rebased[during push] causing the push to fail with 'no such file/directory' error. diff --git a/hgsubversion/wrappers.py b/hgsubversion/wrappers.py --- a/hgsubversion/wrappers.py +++ b/hgsubversion/wrappers.py @@ -14,6 +14,7 @@ from mercurial import i18n from mercurial import extensions from mercurial import repair +import os import replay import pushmod import stupid as stupidmod @@ -287,6 +288,11 @@ def push(repo, dest, force, revs): if not c.node() in hashes and not c.node() in outgoing: util.swap_out_encoding(old_encoding) try: + # Path changed as subdirectories were getting + # deleted during push. + saved_path = os.getcwd() + os.chdir(repo.root) + def extrafn(ctx, extra): extra['branch'] = ctx.branch() @@ -297,6 +303,7 @@ def push(repo, dest, force, revs): rev=[needs_rebase_set], extrafn=extrafn, keep=True) finally: + os.chdir(saved_path) util.swap_out_encoding() diff --git a/tests/test_push_command.py b/tests/test_push_command.py --- a/tests/test_push_command.py +++ b/tests/test_push_command.py @@ -580,6 +580,50 @@ class PushTests(test_util.TestBase): self.assertEqual(commit2.files(), ['gamma']) self.assertFalse(commit2.mutable()) + def test_push_in_subdir(self, commit=True): + repo = self.repo + old_tip = repo['tip'].node() + def file_callback(repo, memctx, path): + if path == 'adding_file' or path == 'newdir/new_file': + testData = 'fooFirstFile' + if path == 'newdir/new_file': + testData = 'fooNewFile' + return context.memfilectx(path=path, + data=testData, + islink=False, + isexec=False, + copied=False) + raise IOError(errno.EINVAL, 'Invalid operation: ' + path) + ctx = context.memctx(repo, + (repo['default'].node(), node.nullid), + 'automated test', + ['adding_file'], + file_callback, + 'an_author', + '2012-12-13 20:59:48 -0500', + {'branch': 'default', }) + new_hash = repo.commitctx(ctx) + p = os.path.join(repo.root, "newdir") + os.mkdir(p) + ctx = context.memctx(repo, + (repo['default'].node(), node.nullid), + 'automated test', + ['newdir/new_file'], + file_callback, + 'an_author', + '2012-12-13 20:59:48 -0500', + {'branch': 'default', }) + os.chdir(p) + new_hash = repo.commitctx(ctx) + hg.update(repo, repo['tip'].node()) + self.pushrevisions() + tip = self.repo['tip'] + self.assertNotEqual(tip.node(), old_tip) + self.assertEqual(p, os.getcwd()) + self.assertEqual(tip['adding_file'].data(), 'fooFirstFile') + self.assertEqual(tip['newdir/new_file'].data(), 'fooNewFile') + self.assertEqual(tip.branch(), 'default') + def suite(): test_classes = [PushTests, ]