From b4b79ac3dbca9088539a10d8d65bfc06504c3c2e Mon Sep 17 00:00:00 2001 From: schu Date: Wed, 15 Feb 2012 00:12:53 +0100 Subject: 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 --- src/commit.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/commit.c') 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) -- cgit v1.2.1