summaryrefslogtreecommitdiff
path: root/src/commit.c
diff options
context:
space:
mode:
authorschu <schu-github@schulog.org>2012-02-15 00:12:53 +0100
committerschu <schu-github@schulog.org>2012-02-15 13:07:41 +0100
commitb4b79ac3dbca9088539a10d8d65bfc06504c3c2e (patch)
tree6e44054215a8de00c4b5e2767c187fb133ee1d2f /src/commit.c
parent66faeb5c5d38541c070a02bc53ad0846a4c5fcc9 (diff)
downloadlibgit2-b4b79ac3dbca9088539a10d8d65bfc06504c3c2e.tar.gz
commit: actually allow yet to be born update_ref
git_commit_create is supposed to update the given reference "update_ref", but segfaulted in case of a yet to be born reference. Fix it. Signed-off-by: schu <schu-github@schulog.org>
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)