summaryrefslogtreecommitdiff
path: root/src/reset.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/reset.c')
-rw-r--r--src/reset.c43
1 files changed, 3 insertions, 40 deletions
diff --git a/src/reset.c b/src/reset.c
index 700aac808..c1e1f865e 100644
--- a/src/reset.c
+++ b/src/reset.c
@@ -13,48 +13,10 @@
#include "git2/reset.h"
#include "git2/checkout.h"
#include "git2/merge.h"
+#include "git2/refs.h"
#define ERROR_MSG "Cannot perform reset"
-static int update_head(git_repository *repo, git_object *commit)
-{
- int error;
- git_reference *head = NULL, *target = NULL;
-
- error = git_repository_head(&head, repo);
-
- if (error < 0 && error != GIT_EORPHANEDHEAD)
- return error;
-
- if (error == GIT_EORPHANEDHEAD) {
- giterr_clear();
-
- /*
- * TODO: This is a bit weak as this doesn't support chained
- * symbolic references. yet.
- */
- if ((error = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0)
- goto cleanup;
-
- if ((error = git_reference_create(
- &target,
- repo,
- git_reference_symbolic_target(head),
- git_object_id(commit), 0)) < 0)
- goto cleanup;
- } else {
- if ((error = git_reference_set_target(head, git_object_id(commit))) < 0)
- goto cleanup;
- }
-
- error = 0;
-
-cleanup:
- git_reference_free(head);
- git_reference_free(target);
- return error;
-}
-
int git_reset_default(
git_repository *repo,
git_object *target,
@@ -167,7 +129,8 @@ int git_reset(
}
/* move HEAD to the new target */
- if ((error = update_head(repo, commit)) < 0)
+ if ((error = git_reference__update_terminal(repo, GIT_HEAD_FILE,
+ git_object_id(commit))) < 0)
goto cleanup;
if (reset_type == GIT_RESET_HARD) {