33
33
TestCaseWithTransport = tests.TestCaseWithTransport
34
34
TestCaseWithMemoryTransport = tests.TestCaseWithMemoryTransport
36
class _DulwichFeature(tests.Feature):
36
class _GitCommandFeature(tests.Feature):
41
except bzr_errors.DependencyNotPresent:
40
p = subprocess.Popen(['git', '--version'], stdout=subprocess.PIPE)
43
out, err = p.communicate()
44
trace.mutter('Using: %s', out.rstrip('\n'))
45
47
def feature_name(self):
49
DulwichFeature = _DulwichFeature()
50
GitCommandFeature = _GitCommandFeature()
54
cmd = ['git'] + list(args)
55
p = subprocess.Popen(cmd,
56
stdout=subprocess.PIPE,
57
stderr=subprocess.PIPE)
58
out, err = p.communicate()
60
raise AssertionError('Bad return code: %d for %s:\n%s'
61
% (p.returncode, ' '.join(cmd), err))
52
65
class GitBranchBuilder(object):
54
67
def __init__(self, stream=None):
55
68
self.commit_info = []
56
self.orig_stream = stream
58
self.stream = StringIO()
62
72
self._branch = 'refs/heads/master'
74
# Write the marks file into the git sandbox.
75
self._marks_file_name = osutils.abspath('marks')
76
self._process = subprocess.Popen(
77
['git', 'fast-import', '--quiet',
78
# GIT doesn't support '--export-marks foo'
79
# it only supports '--export-marks=foo'
80
# And gives a 'unknown option' otherwise.
81
'--export-marks=' + self._marks_file_name,
83
stdout=subprocess.PIPE,
84
stderr=subprocess.PIPE,
85
stdin=subprocess.PIPE,
87
self.stream = self._process.stdin
64
91
def set_branch(self, branch):
65
92
"""Set the branch we are committing."""
66
93
self._branch = branch
68
95
def _write(self, text):
69
self.stream.write(text)
97
self.stream.write(text)
99
if self._process is None:
101
raise errors.GitCommandError(self._process.returncode,
103
self._process.stderr.read())
71
105
def _writelines(self, lines):
72
self.stream.writelines(lines)
107
self.stream.writelines(lines)
109
if self._process is None:
111
raise errors.GitCommandError(self._process.returncode,
113
self._process.stderr.read())
74
115
def _create_blob(self, content):
75
116
self._counter += 1
173
214
def finish(self):
174
215
"""We are finished building, close the stream, get the id mapping"""
176
if self.orig_stream is None:
177
from dulwich.repo import Repo
179
from dulwich.fastexport import FastImporter
180
importer = FastImporter(r)
181
return importer.import_stream(self.stream)
217
if self._process is None:
219
if self._process.wait() != 0:
220
raise errors.GitCommandError(self._process.returncode,
222
self._process.stderr.read())
223
marks_file = open(self._marks_file_name)
225
for line in marks_file:
226
mark, shasum = line.split()
227
assert mark.startswith(':')
228
mapping[int(mark[1:])] = shasum
184
233
def test_suite():
185
loader = tests.TestUtil.TestLoader()
234
loader = tests.TestLoader()
187
suite = tests.TestUtil.TestSuite()
236
suite = tests.TestSuite()
189
238
testmod_names = [
197
245
'test_object_store',
200
247
'test_repository',
206
252
testmod_names = ['%s.%s' % (__name__, t) for t in testmod_names]
207
253
suite.addTests(loader.loadTestsFromModuleNames(testmod_names))