mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 18:22:16 +00:00
commit: support a root commits
A root commit is a commit whose branch (usually what HEAD points to) doesn't exist (yet). This situation can happen when the commit is the first after 1) a repository is initialized or 2) a orphan checkout has been performed. Take this opportunity to remove the symbolic link check, as git_reference_resolve works on OID refs as well. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
This commit is contained in:
parent
68a146c1ae
commit
8381238e00
13
src/commit.c
13
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);
|
||||
|
Loading…
Reference in New Issue
Block a user