Skip to content

Commit d095502

Browse files
committed
tests: don't generate false positives on empty path segments
1 parent e96fc02 commit d095502

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

tests/iterator/workdir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ static void create_paths(const char *root, int depth)
10241024
int i;
10251025

10261026
cl_git_pass(git_buf_puts(&fullpath, root));
1027-
cl_git_pass(git_buf_putc(&fullpath, '/'));
1027+
cl_git_pass(git_path_to_dir(&fullpath));
10281028

10291029
root_len = fullpath.size;
10301030

tests/merge/workdir/setup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static bool test_file_contents(const char *filename, const char *expected)
4949
git_buf file_path_buf = GIT_BUF_INIT, file_buf = GIT_BUF_INIT;
5050
bool equals;
5151

52-
git_buf_printf(&file_path_buf, "%s/%s", git_repository_path(repo), filename);
52+
git_buf_joinpath(&file_path_buf, git_repository_path(repo), filename);
5353

5454
cl_git_pass(git_futils_readbuffer(&file_buf, file_path_buf.ptr));
5555
equals = (strcmp(file_buf.ptr, expected) == 0);
@@ -64,7 +64,7 @@ static void write_file_contents(const char *filename, const char *output)
6464
{
6565
git_buf file_path_buf = GIT_BUF_INIT;
6666

67-
git_buf_printf(&file_path_buf, "%s/%s", git_repository_path(repo),
67+
git_buf_joinpath(&file_path_buf, git_repository_path(repo),
6868
filename);
6969
cl_git_rewritefile(file_path_buf.ptr, output);
7070

tests/odb/foreach.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void test_odb_foreach__files_in_objects_dir(void)
127127
cl_fixture_sandbox("testrepo.git");
128128
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
129129

130-
cl_git_pass(git_buf_printf(&buf, "%s/objects/somefile", git_repository_path(repo)));
130+
cl_git_pass(git_buf_joinpath(&buf, git_repository_path(repo), "objects/somefile"));
131131
cl_git_mkfile(buf.ptr, "");
132132
git_buf_dispose(&buf);
133133

tests/worktree/merge.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ void test_worktree_merge__merge_setup(void)
7070
ours, (const git_annotated_commit **)&theirs, 1));
7171

7272
for (i = 0; i < ARRAY_SIZE(merge_files); i++) {
73-
git_buf_clear(&path);
74-
cl_git_pass(git_buf_printf(&path, "%s/%s",
75-
fixture.worktree->gitdir, merge_files[i]));
73+
cl_git_pass(git_buf_joinpath(&path,
74+
fixture.worktree->gitdir,
75+
merge_files[i]));
7676
cl_assert(git_path_exists(path.ptr));
7777
}
7878

tests/worktree/worktree.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ void test_worktree_worktree__list_with_invalid_worktree_dirs(void)
4444
git_strarray wts;
4545
size_t i, j, len;
4646

47-
cl_git_pass(git_buf_printf(&path, "%s/worktrees/invalid",
48-
fixture.repo->commondir));
47+
cl_git_pass(git_buf_joinpath(&path,
48+
fixture.repo->commondir,
49+
"worktrees/invalid"));
4950
cl_git_pass(p_mkdir(path.ptr, 0755));
5051

5152
len = path.size;
@@ -145,9 +146,9 @@ void test_worktree_worktree__open_invalid_commondir(void)
145146
git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
146147

147148
cl_git_pass(git_buf_sets(&buf, "/path/to/nonexistent/commondir"));
148-
cl_git_pass(git_buf_printf(&path,
149-
"%s/worktrees/testrepo-worktree/commondir",
150-
fixture.repo->commondir));
149+
cl_git_pass(git_buf_joinpath(&path,
150+
fixture.repo->commondir,
151+
"worktrees/testrepo-worktree/commondir"));
151152
cl_git_pass(git_futils_writebuffer(&buf, path.ptr, O_RDWR, 0644));
152153

153154
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
@@ -165,9 +166,9 @@ void test_worktree_worktree__open_invalid_gitdir(void)
165166
git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
166167

167168
cl_git_pass(git_buf_sets(&buf, "/path/to/nonexistent/gitdir"));
168-
cl_git_pass(git_buf_printf(&path,
169-
"%s/worktrees/testrepo-worktree/gitdir",
170-
fixture.repo->commondir));
169+
cl_git_pass(git_buf_joinpath(&path,
170+
fixture.repo->commondir,
171+
"worktrees/testrepo-worktree/gitdir"));
171172
cl_git_pass(git_futils_writebuffer(&buf, path.ptr, O_RDWR, 0644));
172173

173174
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));

0 commit comments

Comments
 (0)