]>
Commit | Line | Data |
---|---|---|
fcc48d1f PK |
1 | #include "clar_libgit2.h" |
2 | #include "refs.h" | |
3 | #include "repo/repo_helpers.h" | |
4 | #include "path.h" | |
5 | #include "fileops.h" | |
6 | ||
7 | static git_repository *g_repo; | |
8 | ||
9 | void test_checkout_binaryunicode__initialize(void) | |
10 | { | |
11 | g_repo = cl_git_sandbox_init("binaryunicode"); | |
12 | } | |
13 | ||
14 | void test_checkout_binaryunicode__cleanup(void) | |
15 | { | |
16 | cl_git_sandbox_cleanup(); | |
17 | } | |
18 | ||
19 | static void execute_test(void) | |
20 | { | |
21 | git_oid oid, check; | |
22 | git_commit *commit; | |
23 | git_tree *tree; | |
24 | git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; | |
25 | ||
26 | cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/branch1")); | |
27 | cl_git_pass(git_commit_lookup(&commit, g_repo, &oid)); | |
28 | cl_git_pass(git_commit_tree(&tree, commit)); | |
29 | ||
30 | opts.checkout_strategy = GIT_CHECKOUT_SAFE; | |
31 | ||
32 | cl_git_pass(git_checkout_tree(g_repo, (git_object *)tree, &opts)); | |
33 | ||
34 | git_tree_free(tree); | |
35 | git_commit_free(commit); | |
36 | ||
37 | /* Verify that the lenna.jpg file was checked out correctly */ | |
38 | cl_git_pass(git_oid_fromstr(&check, "8ab005d890fe53f65eda14b23672f60d9f4ec5a1")); | |
39 | cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/lenna.jpg", GIT_OBJ_BLOB)); | |
40 | cl_assert(git_oid_equal(&oid, &check)); | |
41 | ||
42 | /* Verify that the text file was checked out correctly */ | |
43 | cl_git_pass(git_oid_fromstr(&check, "965b223880dd4249e2c66a0cc0b4cffe1dc40f5a")); | |
44 | cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/utf16_withbom_noeol_crlf.txt", GIT_OBJ_BLOB)); | |
45 | cl_assert(git_oid_equal(&oid, &check)); | |
46 | } | |
47 | ||
48 | void test_checkout_binaryunicode__noautocrlf(void) | |
49 | { | |
50 | git_config *config; | |
51 | ||
52 | cl_git_pass(git_repository_config(&config, g_repo)); | |
53 | cl_git_pass(git_config_set_bool(config, "core.autocrlf", false)); | |
54 | git_config_free(config); | |
55 | ||
56 | execute_test(); | |
57 | } | |
58 | ||
59 | void test_checkout_binaryunicode__autocrlf(void) | |
60 | { | |
61 | git_config *config; | |
62 | ||
63 | cl_git_pass(git_repository_config(&config, g_repo)); | |
64 | cl_git_pass(git_config_set_bool(config, "core.autocrlf", true)); | |
65 | git_config_free(config); | |
66 | ||
67 | execute_test(); | |
68 | } |