Mercurial > hgsubversion
changeset 992:110794582448
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.
author | Kapil Bajaj <kapilbajaj@fb.com> |
---|---|
date | Thu, 17 Jan 2013 17:01:45 -0800 |
parents | 26e9fd21f3bf |
children | b62fff7832c3 |
files | hgsubversion/wrappers.py tests/test_push_command.py |
diffstat | 2 files changed, 51 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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()
--- 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, ]