diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2015-12-09 19:16:11 +0100 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2015-12-09 19:16:11 +0100 |
commit | 465c3b38d59548648521fa4cdbd3d8a832059bb6 (patch) | |
tree | 0800547259b7cf89d0737a1817571aa2574ea2db /src | |
parent | 828852553a6c1704a45463a3681aaa9706d8175c (diff) | |
download | libgit2-cmn/reset-dir-file.tar.gz |
reset: perform the checkout before moving HEAD or the indexcmn/reset-dir-file
This keeps the state of the workdir the same as one from HEAD, removing
a source of possible confusion when calculating the work that is to be
done.
Diffstat (limited to 'src')
-rw-r--r-- | src/reset.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/reset.c b/src/reset.c index 0ffa51b66..f8a1a1dc8 100644 --- a/src/reset.c +++ b/src/reset.c @@ -145,19 +145,19 @@ static int reset( if ((error = git_buf_printf(&log_message, "reset: moving to %s", to)) < 0) return error; - /* move HEAD to the new target */ - if ((error = git_reference__update_terminal(repo, GIT_HEAD_FILE, - git_object_id(commit), NULL, git_buf_cstr(&log_message))) < 0) - goto cleanup; - if (reset_type == GIT_RESET_HARD) { - /* overwrite working directory with HEAD */ + /* overwrite working directory with the new tree */ opts.checkout_strategy = GIT_CHECKOUT_FORCE; if ((error = git_checkout_tree(repo, (git_object *)tree, &opts)) < 0) goto cleanup; } + /* move HEAD to the new target */ + if ((error = git_reference__update_terminal(repo, GIT_HEAD_FILE, + git_object_id(commit), NULL, git_buf_cstr(&log_message))) < 0) + goto cleanup; + if (reset_type > GIT_RESET_SOFT) { /* reset index to the target content */ |