Mercurial > hgsubversion
comparison tests/test_push_dirs.py @ 83:6c9b7cf1c5aa
push_cmd: delete empty svn directories, refactor directory creation
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Fri, 14 Nov 2008 16:18:24 -0600 |
parents | |
children | 01e747937d35 |
comparison
equal
deleted
inserted
replaced
82:71de43e9f614 | 83:6c9b7cf1c5aa |
---|---|
1 import os | |
2 import sys | |
3 import unittest | |
4 | |
5 from mercurial import context | |
6 from mercurial import hg | |
7 from mercurial import node | |
8 | |
9 import test_util | |
10 | |
11 class TestPushDirectories(test_util.TestBase): | |
12 def setUp(self): | |
13 test_util.TestBase.setUp(self) | |
14 test_util.load_fixture_and_fetch('emptyrepo.svndump', | |
15 self.repo_path, | |
16 self.wc_path) | |
17 | |
18 def _commitchanges(self, repo, changes): | |
19 parentctx = repo['tip'] | |
20 | |
21 changed, removed = [], [] | |
22 for source, dest, newdata in changes: | |
23 if dest is None: | |
24 removed.append(source) | |
25 else: | |
26 changed.append(dest) | |
27 | |
28 def filectxfn(repo, memctx, path): | |
29 if path in removed: | |
30 raise IOError() | |
31 entry = [e for e in changes if path == e[1]][0] | |
32 source, dest, newdata = entry | |
33 if newdata is None: | |
34 newdata = parentctx[source].data() | |
35 copied = None | |
36 if source != dest: | |
37 copied = source | |
38 return context.memfilectx(path=dest, | |
39 data=newdata, | |
40 islink=False, | |
41 isexec=False, | |
42 copied=copied) | |
43 | |
44 ctx = context.memctx(repo, | |
45 (parentctx.node(), node.nullid), | |
46 'automated test', | |
47 changed + removed, | |
48 filectxfn, | |
49 'an_author', | |
50 '2008-10-07 20:59:48 -0500') | |
51 nodeid = repo.commitctx(ctx) | |
52 repo = self.repo | |
53 hg.update(repo, nodeid) | |
54 return nodeid | |
55 | |
56 def test_push_dirs(self, commit=True): | |
57 changes = [ | |
58 # Single file in single directory | |
59 ('d1/a', 'd1/a', 'a\n'), | |
60 # Two files in one directory | |
61 ('d2/a', 'd2/a', 'a\n'), | |
62 ('d2/b', 'd2/b', 'a\n'), | |
63 # Single file in empty directory hierarchy | |
64 ('d31/d32/d33/d34/a', 'd31/d32/d33/d34/a', 'a\n'), | |
65 ('d31/d32/a', 'd31/d32/a', 'a\n'), | |
66 ] | |
67 self._commitchanges(self.repo, changes) | |
68 self.pushrevisions() | |
69 self.assertEqual(self.svnls('trunk'), | |
70 ['d1', 'd1/a', 'd2', 'd2/a', 'd2/b', 'd31', | |
71 'd31/d32', 'd31/d32/a', 'd31/d32/d33', | |
72 'd31/d32/d33/d34', 'd31/d32/d33/d34/a']) | |
73 | |
74 changes = [ | |
75 # Remove single file in single directory | |
76 ('d1/a', None, None), | |
77 # Remove one file out of two | |
78 ('d2/a', None, None), | |
79 # Removing this file should remove one empty parent dir too | |
80 ('d31/d32/d33/d34/a', None, None), | |
81 ] | |
82 self._commitchanges(self.repo, changes) | |
83 self.pushrevisions() | |
84 self.assertEqual(self.svnls('trunk'), | |
85 ['d2', 'd2/b', 'd31', 'd31/d32', 'd31/d32/a', 'd31/d32/d33']) | |
86 | |
87 def suite(): | |
88 all = [unittest.TestLoader().loadTestsFromTestCase(TestPushDirectories), | |
89 ] | |
90 return unittest.TestSuite(all) |