]> git.proxmox.com Git - libgit2.git/blob - tests/libgit2/reset/mixed.c
New upstream version 1.5.0+ds
[libgit2.git] / tests / libgit2 / reset / mixed.c
1 #include "clar_libgit2.h"
2 #include "posix.h"
3 #include "reset_helpers.h"
4 #include "path.h"
5
6 static git_repository *repo;
7 static git_object *target;
8
9 void test_reset_mixed__initialize(void)
10 {
11 repo = cl_git_sandbox_init("attr");
12 target = NULL;
13 }
14
15 void test_reset_mixed__cleanup(void)
16 {
17 git_object_free(target);
18 target = NULL;
19
20 cl_git_sandbox_cleanup();
21 }
22
23 void 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
30 cl_git_pass(git_revparse_single(&target, bare, KNOWN_COMMIT_IN_BARE_REPO));
31
32 cl_assert_equal_i(GIT_EBAREREPO, git_reset(bare, target, GIT_RESET_MIXED, NULL));
33
34 git_repository_free(bare);
35 }
36
37 void 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);
43 cl_git_pass(git_revparse_single(&target, repo, "605812a"));
44
45 cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
46
47 cl_git_pass(git_status_file(&status, repo, "macro_bad"));
48 cl_assert(status == GIT_STATUS_WT_NEW);
49 }
50
51 void test_reset_mixed__reflog_is_correct(void)
52 {
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";
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}"));
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);
65
66 git_object_free(target);
67 target = NULL;
68
69 /* Moved branch, expect id in message */
70 cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
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))));
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);
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);
85 }