Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0bb2fc8

Browse files
committed
Commit.create: now handles empty repositories correctly
1 parent15ee0ac commit0bb2fc8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

‎lib/git/objects/commit.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,13 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False):
313313
"""
314314
parents=parent_commits
315315
ifparent_commitsisNone:
316-
parent_commits= [repo.head.commit ]
316+
try:
317+
parent_commits= [repo.head.commit ]
318+
exceptValueError:
319+
# empty repositories have no head commit
320+
parent_commits=list()
321+
# END handle parent commits
322+
# END if parent commits are unset
317323

318324
parent_args= [ ("-p",str(commit))forcommitinparent_commits ]
319325

@@ -331,7 +337,14 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False):
331337
new_commit=cls(repo,commit_sha)
332338

333339
ifhead:
334-
repo.head.commit=new_commit
340+
try:
341+
repo.head.commit=new_commit
342+
exceptValueError:
343+
# head is not yet set to master - create it and set it
344+
importgit.refs
345+
master=git.refs.Head.create(repo,'master',commit=new_commit)
346+
repo.head.reference=master
347+
# END handle empty repositories
335348
# END advance head handling
336349

337350
returnnew_commit

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp