]> git.proxmox.com Git - libgit2.git/blame - tests/libgit2/reset/mixed.c
New upstream version 1.5.0+ds
[libgit2.git] / tests / libgit2 / reset / mixed.c
CommitLineData
edebceff 1#include "clar_libgit2.h"
2#include "posix.h"
3#include "reset_helpers.h"
4#include "path.h"
5
6static git_repository *repo;
7static git_object *target;
8
9void test_reset_mixed__initialize(void)
10{
11 repo = cl_git_sandbox_init("attr");
12 target = NULL;
13}
14
15void test_reset_mixed__cleanup(void)
16{
17 git_object_free(target);
9094d30b
SC
18 target = NULL;
19
edebceff 20 cl_git_sandbox_cleanup();
21}
22
23void test_reset_mixed__cannot_reset_in_a_bare_repository(void)
24{
25 git_repository *bare;
26
27 cl_git_pass(git_repository_open(&bare, cl_fixture("testrepo.git")));
28 cl_assert(git_repository_is_bare(bare) == true);
29
0d847a31 30 cl_git_pass(git_revparse_single(&target, bare, KNOWN_COMMIT_IN_BARE_REPO));
edebceff 31
23a17803 32 cl_assert_equal_i(GIT_EBAREREPO, git_reset(bare, target, GIT_RESET_MIXED, NULL));
edebceff 33
34 git_repository_free(bare);
35}
36
37void test_reset_mixed__resetting_refreshes_the_index_to_the_commit_tree(void)
38{
39 unsigned int status;
40
41 cl_git_pass(git_status_file(&status, repo, "macro_bad"));
42 cl_assert(status == GIT_STATUS_CURRENT);
0d847a31 43 cl_git_pass(git_revparse_single(&target, repo, "605812a"));
edebceff 44
23a17803 45 cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
edebceff 46
47 cl_git_pass(git_status_file(&status, repo, "macro_bad"));
48 cl_assert(status == GIT_STATUS_WT_NEW);
49}
86746b4b
BS
50
51void test_reset_mixed__reflog_is_correct(void)
52{
e579e0f7 53 git_str buf = GIT_STR_INIT;
a5815a2a 54 git_annotated_commit *annotated;
86746b4b
BS
55 const char *exp_msg = "commit: Updating test data so we can test inter-hunk-context";
56
57 reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg);
58 reflog_check(repo, "refs/heads/master", 9, "yoram.harmelin@gmail.com", exp_msg);
59
60 /* Branch not moving, no reflog entry */
61 cl_git_pass(git_revparse_single(&target, repo, "HEAD^{commit}"));
23a17803 62 cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
86746b4b
BS
63 reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg);
64 reflog_check(repo, "refs/heads/master", 9, "yoram.harmelin@gmail.com", exp_msg);
65
ae32c54e
CMN
66 git_object_free(target);
67 target = NULL;
68
a5815a2a 69 /* Moved branch, expect id in message */
86746b4b 70 cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
e579e0f7
MB
71 git_str_clear(&buf);
72 cl_git_pass(git_str_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
23a17803 73 cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
e579e0f7
MB
74 reflog_check(repo, "HEAD", 10, NULL, git_str_cstr(&buf));
75 reflog_check(repo, "refs/heads/master", 10, NULL, git_str_cstr(&buf));
76 git_str_dispose(&buf);
a5815a2a
CMN
77
78 /* Moved branch, expect revspec in message */
79 exp_msg = "reset: moving to HEAD~^{commit}";
80 cl_git_pass(git_annotated_commit_from_revspec(&annotated, repo, "HEAD~^{commit}"));
81 cl_git_pass(git_reset_from_annotated(repo, annotated, GIT_RESET_MIXED, NULL));
82 reflog_check(repo, "HEAD", 11, NULL, exp_msg);
83 reflog_check(repo, "refs/heads/master", 11, NULL, exp_msg);
84 git_annotated_commit_free(annotated);
86746b4b 85}