summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commit.c13
-rw-r--r--src/refs.c3
2 files changed, 13 insertions, 3 deletions
diff --git a/src/commit.c b/src/commit.c
index 9621703c3..0c37ec59b 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -224,9 +224,18 @@ int git_commit_create(
if (error < GIT_SUCCESS)
return error;
- if (git_reference_type(head) == GIT_REF_SYMBOLIC) {
- if ((error = git_reference_resolve(&head, head)) < GIT_SUCCESS)
+ error = git_reference_resolve(&head, head);
+ if (error < GIT_SUCCESS) {
+ if (error != GIT_ENOTFOUND)
return error;
+ /*
+ * The target of the reference was not found. This can happen
+ * just after a repository has been initialized (the master
+ * branch doesn't exist yet, as it doesn't have anything to
+ * point to) or after an orphan checkout, so if the target
+ * branch doesn't exist yet, create it and return.
+ */
+ return git_reference_create_oid_f(&head, repo, git_reference_target(head), oid);
}
error = git_reference_set_oid(head, oid);
diff --git a/src/refs.c b/src/refs.c
index 8c845401f..ea968196f 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -1482,8 +1482,9 @@ int git_reference_resolve(git_reference **resolved_ref, git_reference *ref)
for (i = 0; i < MAX_NESTING_LEVEL; ++i) {
reference_symbolic *ref_sym;
+ *resolved_ref = ref;
+
if (ref->type & GIT_REF_OID) {
- *resolved_ref = ref;
return GIT_SUCCESS;
}