| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -313,7 +313,13 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False): | |||
| 313 | 313 | """ | |
| 314 | 314 | parents = parent_commits | |
| 315 | 315 | if parent_commits is None: | |
| 316 | - parent_commits = [ repo.head.commit ] | ||
| 316 | + try: | ||
| 317 | + parent_commits = [ repo.head.commit ] | ||
| 318 | + except ValueError: | ||
| 319 | + # empty repositories have no head commit | ||
| 320 | + parent_commits = list() | ||
| 321 | + # END handle parent commits | ||
| 322 | + # END if parent commits are unset | ||
| 317 | 323 | ||
| 318 | 324 | parent_args = [ ("-p", str(commit)) for commit in parent_commits ] | |
| 319 | 325 | ||
@@ -331,7 +337,14 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False): | |||
| 331 | 337 | new_commit = cls(repo, commit_sha) | |
| 332 | 338 | ||
| 333 | 339 | if head: | |
| 334 | - repo.head.commit = new_commit | ||
| 340 | + try: | ||
| 341 | + repo.head.commit = new_commit | ||
| 342 | + except ValueError: | ||
| 343 | + # head is not yet set to master - create it and set it | ||
| 344 | + import git.refs | ||
| 345 | + master = git.refs.Head.create(repo, 'master', commit=new_commit) | ||
| 346 | + repo.head.reference = master | ||
| 347 | + # END handle empty repositories | ||
| 335 | 348 | # END advance head handling | |
| 336 | 349 | ||
| 337 | 350 | return new_commit | |
| Back | FazBrowse Home | New Git URL |
0 commit comments