Page MenuHomeSoftware Heritage
Paste P510

dulwich-based fake date git commit proto-prototype
ActivePublic

Authored by olasd on Aug 20 2019, 2:40 PM.
#!/usr/bin/env python3
import sys
import dateutil.parser
import dulwich.repo
def commit(repo, timestamp,
author=b'Software Heritage <test@softwareheritage.org>',
message='Commit test\n', ref=b'HEAD'):
"""Commit the current working tree in a new commit with message on
the branch 'ref'.
At the end of the commit, the reference should stay the same
and the index should be clean.
"""
message = message.encode()
ret = repo.do_commit(
message=message, committer=author,
commit_timestamp=timestamp,
commit_timezone=0,
ref=ref)
return ret
if __name__ == '__main__':
repo = dulwich.repo.Repo('.')
date = sys.argv[1]
timestamp = dateutil.parser.parse(date).timestamp()
print(date, timestamp)
commit(repo, timestamp)