|
5 | 5 |
|
6 | 6 | static git_repository *repo1; |
7 | 7 | static git_repository *repo2; |
| 8 | +static char* repo1_path; |
| 9 | +static char* repo2_path; |
8 | 10 |
|
9 | 11 | static const char *REPO1_REFNAME = "refs/heads/main"; |
10 | 12 | static const char *REPO2_REFNAME = "refs/remotes/repo1/main"; |
11 | 13 | static char *FORCE_FETCHSPEC = "+refs/heads/main:refs/remotes/repo1/main"; |
12 | 14 | static char *NON_FORCE_FETCHSPEC = "refs/heads/main:refs/remotes/repo1/main"; |
13 | 15 |
|
14 | 16 | char* strip_trailing_slash(char *path) { |
15 | | - char *result = NULL; |
16 | 17 | if (path[strlen(path) - 1] == '/') { |
17 | | - result = (char *) malloc(strlen(path) - 1); |
| 18 | + char* result = (char *) calloc(strlen(path) - 1, sizeof(char)); |
18 | 19 | memcpy(result, path, strlen(path) - 1); |
| 20 | + return result; |
19 | 21 | } else { |
20 | | - result = (char *) malloc(strlen(path)); |
| 22 | + char* result = (char *) calloc(strlen(path), sizeof(char)); |
21 | 23 | strncpy(result, path, strlen(path)); |
| 24 | + return result; |
22 | 25 | } |
23 | | - return result; |
24 | 26 | } |
25 | 27 |
|
26 | 28 |
|
27 | 29 | void test_remote_fetch__initialize(void) { |
28 | 30 | git_config *c; |
29 | | - git_buf repo1_path = GIT_BUF_INIT; |
30 | | - git_buf repo2_path = GIT_BUF_INIT; |
| 31 | + git_buf repo1_path_buf = GIT_BUF_INIT; |
| 32 | + git_buf repo2_path_buf = GIT_BUF_INIT; |
31 | 33 | const char *sandbox = clar_sandbox_path(); |
32 | 34 |
|
33 | | - cl_git_pass(git_buf_join(&repo1_path, '/', sandbox, "fetchtest_repo1")); |
34 | | - cl_git_pass(git_repository_init(&repo1, repo1_path.ptr, true)); |
| 35 | + cl_git_pass(git_buf_join(&repo1_path_buf, '/', sandbox, "fetchtest_repo1")); |
| 36 | + repo1_path = calloc(repo1_path_buf.size, sizeof(char)); |
| 37 | + git_buf_copy_cstr(repo1_path, repo1_path_buf.size, &repo1_path_buf); |
| 38 | + cl_git_pass(git_repository_init(&repo1, repo1_path, true)); |
35 | 39 |
|
36 | | - cl_git_pass(git_buf_join(&repo2_path, '/', sandbox, "fetchtest_repo2")); |
37 | | - cl_git_pass(git_repository_init(&repo2, repo2_path.ptr, true)); |
| 40 | + cl_git_pass(git_buf_join(&repo2_path_buf, '/', sandbox, "fetchtest_repo2")); |
| 41 | + repo2_path = calloc(repo2_path_buf.size, sizeof(char)); |
| 42 | + git_buf_copy_cstr(repo2_path, repo2_path_buf.size, &repo2_path_buf); |
| 43 | + cl_git_pass(git_repository_init(&repo2, repo2_path, true)); |
38 | 44 |
|
39 | 45 | cl_git_pass(git_repository_config(&c, repo1)); |
40 | 46 | cl_git_pass(git_config_set_string(c, "user.email", "some@email")); |
41 | 47 | cl_git_pass(git_config_set_string(c, "user.name", "some@name")); |
42 | 48 | git_config_free(c); |
43 | | - git_buf_dispose(&repo1_path); |
44 | | - git_buf_dispose(&repo2_path); |
| 49 | + git_buf_dispose(&repo1_path_buf); |
| 50 | + git_buf_dispose(&repo2_path_buf); |
45 | 51 | } |
46 | 52 |
|
47 | 53 | void test_remote_fetch__cleanup(void) { |
48 | | - char *repo1_path = strip_trailing_slash(repo1->gitdir); |
49 | | - char *repo2_path = strip_trailing_slash(repo2->gitdir); |
50 | | - |
51 | 54 | git_repository_free(repo1); |
52 | 55 | git_repository_free(repo2); |
53 | 56 |
|
|
0 commit comments