Allow using fast_import for more than initial commit.
This commit is contained in:
parent
be91386b45
commit
895fd8b7ad
2 changed files with 40 additions and 4 deletions
|
@ -63,6 +63,7 @@ def fast_import(
|
|||
commit_msg,
|
||||
committer,
|
||||
files,
|
||||
parent=None,
|
||||
):
|
||||
"""
|
||||
Create an initial commit.
|
||||
|
@ -97,10 +98,17 @@ committer %(committer)s now
|
|||
data %(commit_msg_len)d
|
||||
%(commit_msg)s
|
||||
""" % dict(
|
||||
committer=committer,
|
||||
commit_msg_len=len(commit_msg),
|
||||
commit_msg=commit_msg,
|
||||
))
|
||||
committer=committer,
|
||||
commit_msg_len=len(commit_msg),
|
||||
commit_msg=commit_msg,
|
||||
))
|
||||
if parent is not None:
|
||||
assert not parent.startswith(':')
|
||||
child.stdin.write("""\
|
||||
from %(parent)s
|
||||
""" % dict(
|
||||
parent=parent,
|
||||
))
|
||||
for index, (path, content) in enumerate(files):
|
||||
child.stdin.write('M 100644 :%d %s\n' % (index+1, path))
|
||||
child.stdin.close()
|
||||
|
|
|
@ -313,3 +313,31 @@ exec git "$@"
|
|||
got = readFile(os.path.join(tmp, 'cookie'))
|
||||
eq(got, magic_cookie)
|
||||
|
||||
def test_fast_import_parent():
|
||||
tmp = maketemp()
|
||||
path = os.path.join(tmp, 'repo.git')
|
||||
repository.init(path=path)
|
||||
repository.fast_import(
|
||||
git_dir=path,
|
||||
commit_msg='foo initial bar',
|
||||
committer='Mr. Unit Test <unit.test@example.com>',
|
||||
files=[
|
||||
('foo', 'bar\n'),
|
||||
],
|
||||
)
|
||||
repository.fast_import(
|
||||
git_dir=path,
|
||||
commit_msg='another',
|
||||
committer='Sam One Else <sam@example.com>',
|
||||
parent='refs/heads/master^0',
|
||||
files=[
|
||||
('quux', 'thud\n'),
|
||||
],
|
||||
)
|
||||
export = os.path.join(tmp, 'export')
|
||||
repository.export(
|
||||
git_dir=path,
|
||||
path=export,
|
||||
)
|
||||
eq(sorted(os.listdir(export)),
|
||||
sorted(['foo', 'quux']))
|
||||
|
|
Loading…
Reference in a new issue