summaryrefslogtreecommitdiff
path: root/src/commit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/commit.c')
-rw-r--r--src/commit.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/commit.c b/src/commit.c
index 64db0a707..189d8fe9e 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -146,10 +146,14 @@ int git_commit_create(
git_reference *target;
error = git_reference_lookup(&head, repo, update_ref);
- if (error < GIT_SUCCESS)
+ if (error < GIT_SUCCESS && error != GIT_ENOTFOUND)
return git__rethrow(error, "Failed to create commit");
- error = git_reference_resolve(&target, head);
+ if (error != GIT_ENOTFOUND) {
+ update_ref = git_reference_target(head);
+ error = git_reference_resolve(&target, head);
+ }
+
if (error < GIT_SUCCESS) {
if (error != GIT_ENOTFOUND) {
git_reference_free(head);
@@ -162,7 +166,7 @@ int git_commit_create(
* point to) or after an orphan checkout, so if the target
* branch doesn't exist yet, create it and return.
*/
- error = git_reference_create_oid(&target, repo, git_reference_target(head), oid, 1);
+ error = git_reference_create_oid(&target, repo, update_ref, oid, 1);
git_reference_free(head);
if (error == GIT_SUCCESS)