1 #include "clar_libgit2.h"
3 #include "reset_helpers.h"
6 static git_repository
*repo
;
7 static git_object
*target
;
9 void test_reset_mixed__initialize(void)
11 repo
= cl_git_sandbox_init("attr");
15 void test_reset_mixed__cleanup(void)
17 git_object_free(target
);
20 cl_git_sandbox_cleanup();
23 void test_reset_mixed__cannot_reset_in_a_bare_repository(void)
27 cl_git_pass(git_repository_open(&bare
, cl_fixture("testrepo.git")));
28 cl_assert(git_repository_is_bare(bare
) == true);
30 cl_git_pass(git_revparse_single(&target
, bare
, KNOWN_COMMIT_IN_BARE_REPO
));
32 cl_assert_equal_i(GIT_EBAREREPO
, git_reset(bare
, target
, GIT_RESET_MIXED
, NULL
));
34 git_repository_free(bare
);
37 void test_reset_mixed__resetting_refreshes_the_index_to_the_commit_tree(void)
41 cl_git_pass(git_status_file(&status
, repo
, "macro_bad"));
42 cl_assert(status
== GIT_STATUS_CURRENT
);
43 cl_git_pass(git_revparse_single(&target
, repo
, "605812a"));
45 cl_git_pass(git_reset(repo
, target
, GIT_RESET_MIXED
, NULL
));
47 cl_git_pass(git_status_file(&status
, repo
, "macro_bad"));
48 cl_assert(status
== GIT_STATUS_WT_NEW
);
51 void test_reset_mixed__reflog_is_correct(void)
53 git_str buf
= GIT_STR_INIT
;
54 git_annotated_commit
*annotated
;
55 const char *exp_msg
= "commit: Updating test data so we can test inter-hunk-context";
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
);
60 /* Branch not moving, no reflog entry */
61 cl_git_pass(git_revparse_single(&target
, repo
, "HEAD^{commit}"));
62 cl_git_pass(git_reset(repo
, target
, GIT_RESET_MIXED
, NULL
));
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
);
66 git_object_free(target
);
69 /* Moved branch, expect id in message */
70 cl_git_pass(git_revparse_single(&target
, repo
, "HEAD~^{commit}"));
72 cl_git_pass(git_str_printf(&buf
, "reset: moving to %s", git_oid_tostr_s(git_object_id(target
))));
73 cl_git_pass(git_reset(repo
, target
, GIT_RESET_MIXED
, NULL
));
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
);
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
);