comparison tests/test_util.py @ 84:01e747937d35

test_util: add commitchanges() to TestBase
author Patrick Mezard <pmezard@gmail.com>
date Fri, 14 Nov 2008 16:18:24 -0600
parents 6c9b7cf1c5aa
children 7d10165cf3d9
comparison
equal deleted inserted replaced
83:6c9b7cf1c5aa 84:01e747937d35
5 import stat 5 import stat
6 import tempfile 6 import tempfile
7 import unittest 7 import unittest
8 import urllib 8 import urllib
9 9
10 from mercurial import context
11 from mercurial import hg
12 from mercurial import node
10 from mercurial import ui 13 from mercurial import ui
11 from mercurial import hg
12 14
13 import fetch_command 15 import fetch_command
14 import push_cmd 16 import push_cmd
15 17
16 FIXTURES = os.path.join(os.path.abspath(os.path.dirname(__file__)), 18 FIXTURES = os.path.join(os.path.abspath(os.path.dirname(__file__)),
93 if p.returncode: 95 if p.returncode:
94 raise Exception('svn ls failed on %s: %r' % (path, stderr)) 96 raise Exception('svn ls failed on %s: %r' % (path, stderr))
95 entries = [e.strip('/') for e in stdout.splitlines()] 97 entries = [e.strip('/') for e in stdout.splitlines()]
96 entries.sort() 98 entries.sort()
97 return entries 99 return entries
100
101 def commitchanges(self, changes):
102 """Commit changes to mercurial directory
103
104 'changes' is a sequence of tuples (source, dest, data). It can look
105 like:
106 - (source, source, data) to set source content to data
107 - (source, dest, None) to set dest content to source one, and mark it as
108 copied from source.
109 - (source, dest, data) to set dest content to data, and mark it as copied
110 from source.
111 - (source, None, None) to remove source.
112 """
113 repo = self.repo
114 parentctx = repo['tip']
115
116 changed, removed = [], []
117 for source, dest, newdata in changes:
118 if dest is None:
119 removed.append(source)
120 else:
121 changed.append(dest)
122
123 def filectxfn(repo, memctx, path):
124 if path in removed:
125 raise IOError()
126 entry = [e for e in changes if path == e[1]][0]
127 source, dest, newdata = entry
128 if newdata is None:
129 newdata = parentctx[source].data()
130 copied = None
131 if source != dest:
132 copied = source
133 return context.memfilectx(path=dest,
134 data=newdata,
135 islink=False,
136 isexec=False,
137 copied=copied)
138
139 ctx = context.memctx(repo,
140 (parentctx.node(), node.nullid),
141 'automated test',
142 changed + removed,
143 filectxfn,
144 'an_author',
145 '2008-10-07 20:59:48 -0500')
146 nodeid = repo.commitctx(ctx)
147 repo = self.repo
148 hg.update(repo, nodeid)
149 return nodeid