[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 = []
for commit in commits:
if commit.reset:
tree = None
r = self._session.post('https://api.github.com/repos/{}/git/trees'.format(self.name), json={
'tree': [
{'path': k, 'mode': '100644', 'type': 'blob', 'content': v}
for k, v in commit.tree.items()
],
'base_tree': tree
})
assert r.ok, r.text
tree = r.json()['sha']
if commit.tree:
if commit.reset:
tree = None
r = self._session.post('https://api.github.com/repos/{}/git/trees'.format(self.name), json={
'tree': [
{'path': k, 'mode': '100644', 'type': 'blob', 'content': v}
for k, v in commit.tree.items()
],
'base_tree': tree
})
assert r.ok, r.text
tree = r.json()['sha']
data = {
'parents': parents,