summaryrefslogtreecommitdiff
path: root/src/libgit2/repository.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libgit2/repository.c')
-rw-r--r--src/libgit2/repository.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c
index d2fe1e6bb..97f776c4a 100644
--- a/src/libgit2/repository.c
+++ b/src/libgit2/repository.c
@@ -3422,12 +3422,18 @@ cleanup:
static int checkout_message(git_str *out, git_reference *old, const char *new)
{
+ const char *idstr;
+
git_str_puts(out, "checkout: moving from ");
- if (git_reference_type(old) == GIT_REFERENCE_SYMBOLIC)
+ if (git_reference_type(old) == GIT_REFERENCE_SYMBOLIC) {
git_str_puts(out, git_reference__shorthand(git_reference_symbolic_target(old)));
- else
- git_str_puts(out, git_oid_tostr_s(git_reference_target(old)));
+ } else {
+ if ((idstr = git_oid_tostr_s(git_reference_target(old))) == NULL)
+ return -1;
+
+ git_str_puts(out, idstr);
+ }
git_str_puts(out, " to ");
@@ -3463,8 +3469,11 @@ static int detach(git_repository *repo, const git_oid *id, const char *new)
if ((error = git_object_peel(&peeled, object, GIT_OBJECT_COMMIT)) < 0)
goto cleanup;
- if (new == NULL)
- new = git_oid_tostr_s(git_object_id(peeled));
+ if (new == NULL &&
+ (new = git_oid_tostr_s(git_object_id(peeled))) == NULL) {
+ error = -1;
+ goto cleanup;
+ }
if ((error = checkout_message(&log_message, current, new)) < 0)
goto cleanup;
@@ -3552,6 +3561,7 @@ int git_repository_detach_head(git_repository *repo)
git_reference *old_head = NULL, *new_head = NULL, *current = NULL;
git_object *object = NULL;
git_str log_message = GIT_STR_INIT;
+ const char *idstr;
int error;
GIT_ASSERT_ARG(repo);
@@ -3565,7 +3575,12 @@ int git_repository_detach_head(git_repository *repo)
if ((error = git_object_lookup(&object, repo, git_reference_target(old_head), GIT_OBJECT_COMMIT)) < 0)
goto cleanup;
- if ((error = checkout_message(&log_message, current, git_oid_tostr_s(git_object_id(object)))) < 0)
+ if ((idstr = git_oid_tostr_s(git_object_id(object))) == NULL) {
+ error = -1;
+ goto cleanup;
+ }
+
+ if ((error = checkout_message(&log_message, current, idstr)) < 0)
goto cleanup;
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head),