1 #include "clar_libgit2.h"
3 #include "git2/checkout.h"
10 static git_repository
*repo
;
11 static git_object
*obj
;
12 static git_checkout_options checkout_opts
;
14 void test_checkout_icase__initialize(void)
18 repo
= cl_git_sandbox_init("testrepo");
20 cl_git_pass(git_reference_name_to_id(&id
, repo
, "refs/heads/dir"));
21 cl_git_pass(git_object_lookup(&obj
, repo
, &id
, GIT_OBJ_ANY
));
23 git_checkout_init_options(&checkout_opts
, GIT_CHECKOUT_OPTIONS_VERSION
);
24 checkout_opts
.checkout_strategy
= GIT_CHECKOUT_FORCE
;
27 void test_checkout_icase__cleanup(void)
30 cl_git_sandbox_cleanup();
33 static char *test_realpath(const char *in
)
40 typedef DWORD (__stdcall
*getfinalpathname
)(HANDLE
, LPSTR
, DWORD
, DWORD
);
41 getfinalpathname getfinalpathfn
;
43 cl_assert(filename
= malloc(MAX_PATH
));
44 cl_assert(kerneldll
= LoadLibrary("kernel32.dll"));
45 cl_assert(getfinalpathfn
= (getfinalpathname
)GetProcAddress(kerneldll
, "GetFinalPathNameByHandleA"));
47 cl_assert(fh
= CreateFileA(in
, FILE_READ_ATTRIBUTES
| STANDARD_RIGHTS_READ
, FILE_SHARE_READ
,
48 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, NULL
));
50 cl_win32_pass(getfinalpathfn(fh
, filename
, MAX_PATH
, VOLUME_NAME_DOS
));
54 git_path_mkposix(filename
);
58 return realpath(in
, NULL
);
62 static void assert_name_is(const char *expected
)
65 size_t actual_len
, expected_len
, start
;
67 cl_assert(actual
= test_realpath(expected
));
69 expected_len
= strlen(expected
);
70 actual_len
= strlen(actual
);
71 cl_assert(actual_len
>= expected_len
);
73 start
= actual_len
- expected_len
;
74 cl_assert_equal_s(expected
, actual
+ start
);
77 cl_assert_equal_strn("/", actual
+ (start
- 1), 1);
82 void test_checkout_icase__overwrites_files_for_files(void)
84 cl_git_write2file("testrepo/NEW.txt", "neue file\n", 10, \
85 O_WRONLY
| O_CREAT
| O_TRUNC
, 0644);
87 cl_git_pass(git_checkout_tree(repo
, obj
, &checkout_opts
));
88 assert_name_is("testrepo/new.txt");
91 void test_checkout_icase__overwrites_links_for_files(void)
93 cl_must_pass(p_symlink("../tmp", "testrepo/NEW.txt"));
95 cl_git_pass(git_checkout_tree(repo
, obj
, &checkout_opts
));
97 cl_assert(!git_path_exists("tmp"));
98 assert_name_is("testrepo/new.txt");
101 void test_checkout_icase__overwites_folders_for_files(void)
103 cl_must_pass(p_mkdir("testrepo/NEW.txt", 0777));
105 cl_git_pass(git_checkout_tree(repo
, obj
, &checkout_opts
));
107 assert_name_is("testrepo/new.txt");
108 cl_assert(!git_path_isdir("testrepo/new.txt"));
111 void test_checkout_icase__overwrites_files_for_folders(void)
113 cl_git_write2file("testrepo/A", "neue file\n", 10, \
114 O_WRONLY
| O_CREAT
| O_TRUNC
, 0644);
116 cl_git_pass(git_checkout_tree(repo
, obj
, &checkout_opts
));
117 assert_name_is("testrepo/a");
118 cl_assert(git_path_isdir("testrepo/a"));
121 void test_checkout_icase__overwrites_links_for_folders(void)
123 cl_must_pass(p_symlink("..", "testrepo/A"));
125 cl_git_pass(git_checkout_tree(repo
, obj
, &checkout_opts
));
127 cl_assert(!git_path_exists("b.txt"));
128 assert_name_is("testrepo/a");