61
class GitBranchBuilder(object):
63
def __init__(self, stream):
67
self._branch = 'refs/head/master'
69
def set_branch(self, branch):
70
"""Set the branch we are committing."""
73
def _create_blob(self, content):
75
self.stream.write('blob\n')
76
self.stream.write('mark :%d\n' % (self._counter,))
77
self.stream.write('data %d\n' % (len(content),))
78
self.stream.write(content)
79
self.stream.write('\n')
82
def set_file(self, path, content, executable):
83
"""Create or update content at a given path."""
84
mark = self._create_blob(content)
89
self.commit_info.append('M %s :%d %s\n'
90
% (mode, mark, path.encode('utf-8')))
92
def set_link(self, path, link_target):
93
"""Create or update a link at a given path."""
94
mark = self._create_blob(link_target)
95
self.commit_info.append('M 120000 :%d %s\n'
96
% (mark, path.encode('utf-8')))
98
def delete_entry(self, path):
99
"""This will delete files or symlinks at the given location."""
100
self.commit_info.append('D %s\n' % (path.encode('utf-8'),))
102
def commit(self, committer, message, timestamp=None,
103
timezone='+0000', author=None):
106
self.stream.write('commit %s\n' % (branch,))
107
self.stream.write('mark :%d\n' % (mark,))
108
self.stream.write('committer %s %s %s\n'
109
% (committer, timestamp, timezone))
110
message = message.encode('UTF-8')
111
self.stream.write('data %d\n' % (len(message),))
112
self.stream.write(message)
113
self.stream.write('\n')
114
self.stream.writelines(self.commit_info)
115
self.stream.write('\n')
116
self.commit_info = []
120
class GitBranchBuilder(object):
121
"""This uses git-fast-import to build up something directly."""
123
def __init__(self, git_dir):
124
self.git_dir = git_dir
61
128
loader = tests.TestLoader()
63
130
suite = tests.TestSuite()
66
134
'test_git_branch',
68
136
'test_git_repository',