[ADD] *: support for empty commits

The Commit test object now allows a tree of `None` (or an empty dict,
same diff) in which case it will create an empty commit (a commit
which uses the same tree as its parent).
This commit is contained in:
Xavier Morel 2021-11-16 13:59:58 +01:00
parent 3cdcba2f26
commit b0995adda0

View File

@ -650,17 +650,18 @@ class Repo:
hashes = [] hashes = []
for commit in commits: for commit in commits:
if commit.reset: if commit.tree:
tree = None if commit.reset:
r = self._session.post('https://api.github.com/repos/{}/git/trees'.format(self.name), json={ tree = None
'tree': [ r = self._session.post('https://api.github.com/repos/{}/git/trees'.format(self.name), json={
{'path': k, 'mode': '100644', 'type': 'blob', 'content': v} 'tree': [
for k, v in commit.tree.items() {'path': k, 'mode': '100644', 'type': 'blob', 'content': v}
], for k, v in commit.tree.items()
'base_tree': tree ],
}) 'base_tree': tree
assert r.ok, r.text })
tree = r.json()['sha'] assert r.ok, r.text
tree = r.json()['sha']
data = { data = {
'parents': parents, 'parents': parents,