Branch Coverage

deps/libgit2/src/libgit2/worktree.c
Criterion Covered Total %
branch 134 252 53.1


line true false branch
23 0 12 if (git_str_sets(&buf, dir) < 0)
27 10 0 && git_fs_path_contains_file(&buf, "gitdir")
28 10 2 && git_fs_path_contains_file(&buf, "HEAD");
10 0 && git_fs_path_contains_file(&buf, "HEAD");
42 0 20 GIT_ASSERT_ARG(wts);
43 0 20 GIT_ASSERT_ARG(repo);
48 0 20 if ((error = git_str_joinpath(&path, repo->commondir, "worktrees/")) < 0)
50 2 18 if (!git_fs_path_exists(path.ptr) || git_fs_path_is_empty_dir(path.ptr))
2 0 if (!git_fs_path_exists(path.ptr) || git_fs_path_is_empty_dir(path.ptr))
52 0 2 if ((error = git_fs_path_dirload(&worktrees, path.ptr, path.size, 0x0)) < 0)
57 4 2 git_vector_foreach(&worktrees, i, worktree) {
61 0 4 if (!is_worktree_dir(path.ptr)) {
79 0 71 GIT_ASSERT_ARG_WITH_RETVAL(base, NULL);
80 0 71 GIT_ASSERT_ARG_WITH_RETVAL(file, NULL);
82 0 71 if (git_str_joinpath(&path, base, file) < 0)
84 58 13 if (git_futils_readbuffer(&buf, path.ptr) < 0)
90 13 0 if (!git_fs_path_is_relative(buf.ptr))
93 0 0 if (git_str_sets(&path, base) < 0)
95 0 0 if (git_fs_path_apply_relative(&path, buf.ptr) < 0)
113 0 6 GIT_ASSERT_ARG(base);
114 0 6 GIT_ASSERT_ARG(file);
115 0 6 GIT_ASSERT_ARG(buf);
117 0 6 if ((err = git_str_joinpath(&path, base, file)) < 0)
120 0 6 if ((err = git_futils_writebuffer(buf, path.ptr, O_CREAT|O_EXCL|O_WRONLY, 0644)) < 0)
135 1 4 if (!is_worktree_dir(dir)) {
140 0 4 if ((error = git_path_validate_length(NULL, dir)) < 0)
143 0 4 if ((wt = git__calloc(1, sizeof(*wt))) == NULL) {
149 4 0 (wt->commondir_path = git_worktree__read_link(dir, "commondir")) == NULL ||
150 4 0 (wt->gitlink_path = git_worktree__read_link(dir, "gitdir")) == NULL ||
157 0 4 if ((error = git_fs_path_prettify_dir(&gitdir, dir, NULL)) < 0)
161 0 4 if ((error = git_worktree_is_locked(NULL, wt)) < 0)
169 1 4 if (error)
182 0 5 GIT_ASSERT_ARG(repo);
183 0 5 GIT_ASSERT_ARG(name);
187 0 5 if ((error = git_str_join3(&path, '/', repo->commondir, "worktrees", name)) < 0)
190 1 4 if ((error = (open_worktree_dir(out, git_repository_workdir(repo), path.ptr, name))) < 0)
196 1 4 if (error)
209 0 0 if (!git_repository_is_worktree(repo)) {
218 0 0 if ((error = git_fs_path_prettify_dir(&parent, "..", commondir)) < 0)
224 0 0 if ((error = open_worktree_dir(out, parent.ptr, gitdir, name)) < 0)
236 20 4 if (!wt)
250 0 3 GIT_ASSERT_ARG(wt);
252 1 2 if (!is_worktree_dir(wt->gitdir_path)) {
259 2 0 if (wt->parent_path && !git_fs_path_exists(wt->parent_path)) {
0 2 if (wt->parent_path && !git_fs_path_exists(wt->parent_path)) {
266 0 2 if (!git_fs_path_exists(wt->commondir_path)) {
273 0 2 if (!git_fs_path_exists(wt->worktree_path)) {
286 0 0 GIT_INIT_STRUCTURE_FROM_TEMPLATE(opts, version,
311 0 2 GIT_ERROR_CHECK_VERSION(
314 0 2 GIT_ASSERT_ARG(out);
315 0 2 GIT_ASSERT_ARG(repo);
316 0 2 GIT_ASSERT_ARG(name);
317 0 2 GIT_ASSERT_ARG(worktree);
321 0 2 if (opts)
326 0 2 if (wtopts.ref) {
327 0 0 if (!git_reference_is_branch(wtopts.ref)) {
333 0 0 if (git_branch_is_checked_out(wtopts.ref)) {
341 0 2 if ((err = git_str_joinpath(&gitdir, repo->commondir, "worktrees")) < 0)
343 1 1 if (!git_fs_path_exists(gitdir.ptr))
344 0 1 if ((err = git_futils_mkdir(gitdir.ptr, 0755, GIT_MKDIR_EXCL)) < 0)
346 0 2 if ((err = git_str_joinpath(&gitdir, gitdir.ptr, name)) < 0)
348 0 2 if ((err = git_futils_mkdir(gitdir.ptr, 0755, GIT_MKDIR_EXCL)) < 0)
350 0 2 if ((err = git_fs_path_prettify_dir(&gitdir, gitdir.ptr, NULL)) < 0)
354 0 2 if ((err = git_futils_mkdir(worktree, 0755, GIT_MKDIR_EXCL)) < 0)
356 0 2 if ((err = git_fs_path_prettify_dir(&wddir, worktree, NULL)) < 0)
359 0 2 if (wtopts.lock) {
362 0 0 if ((err = git_str_joinpath(&buf, gitdir.ptr, "locked")) < 0)
365 0 0 if ((fd = p_creat(buf.ptr, 0644)) < 0) {
375 0 2 if ((err = git_str_printf(&buf, "gitdir: %s\n", gitdir.ptr)) < 0)
377 0 2 if ((err = write_wtfile(wddir.ptr, ".git", &buf)) < 0)
381 2 0 if ((err = git_fs_path_prettify_dir(&buf, repo->commondir, NULL) < 0)
382 2 0 || (err = git_str_putc(&buf, '\n')) < 0
383 2 0 || (err = write_wtfile(gitdir.ptr, "commondir", &buf)) < 0)
385 2 0 if ((err = git_str_joinpath(&buf, wddir.ptr, ".git")) < 0
386 2 0 || (err = git_str_putc(&buf, '\n')) < 0
387 2 0 || (err = write_wtfile(gitdir.ptr, "gitdir", &buf)) < 0)
391 0 2 if (wtopts.ref) {
392 0 0 if ((err = git_reference_dup(&ref, wtopts.ref)) < 0)
395 0 2 if ((err = git_repository_head(&head, repo)) < 0)
397 0 2 if ((err = git_commit_lookup(&commit, repo, &head->target.oid)) < 0)
399 0 2 if ((err = git_branch_create(&ref, repo, name, commit, false)) < 0)
404 0 2 if ((err = git_repository_create_head(gitdir.ptr, git_reference_name(ref))) < 0)
406 0 2 if ((err = git_repository_open(&wt, wddir.ptr)) < 0)
410 0 2 if ((err = git_checkout_head(wt, &coopts)) < 0)
414 0 2 if ((err = git_worktree_lookup(out, repo, name)) < 0)
434 0 3 GIT_ASSERT_ARG(wt);
436 0 3 if ((error = git_worktree_is_locked(NULL, wt)) < 0)
438 1 2 if (error) {
443 0 2 if ((error = git_str_joinpath(&path, wt->gitdir_path, "locked")) < 0)
446 2 0 if (reason)
449 0 2 if ((error = git_futils_writebuffer(&buf, path.ptr, O_CREAT|O_EXCL|O_WRONLY, 0644)) < 0)
465 0 1 GIT_ASSERT_ARG(wt);
467 0 1 if ((error = git_worktree_is_locked(NULL, wt)) < 0)
469 0 1 if (!error)
472 0 1 if (git_str_joinpath(&path, wt->gitdir_path, "locked") < 0)
475 0 1 if (p_unlink(path.ptr) != 0) {
492 0 14 GIT_ASSERT_ARG(wt);
494 6 8 if (reason)
497 0 14 if ((error = git_str_joinpath(&path, wt->gitdir_path, "locked")) < 0)
500 4 10 if (locked && reason &&
2 2 if (locked && reason &&
0 2 if (locked && reason &&
516 3 8 if (reason && (error = git_buf_tostr(&str, reason)) < 0)
0 3 if (reason && (error = git_buf_tostr(&str, reason)) < 0)
519 3 8 error = git_worktree__is_locked(reason ? &str : NULL, wt);
521 11 0 if (error >= 0 && reason) {
3 8 if (error >= 0 && reason) {
522 0 3 if (git_buf_fromstr(reason, &str) < 0)
532 0 2 GIT_ASSERT_ARG_WITH_RETVAL(wt, NULL);
538 0 2 GIT_ASSERT_ARG_WITH_RETVAL(wt, NULL);
546 0 0 GIT_INIT_STRUCTURE_FROM_TEMPLATE(opts, version,
564 0 6 GIT_ERROR_CHECK_VERSION(
568 6 0 if (opts)
571 3 3 if ((popts.flags & GIT_WORKTREE_PRUNE_LOCKED) == 0) {
575 0 3 if ((error = git_worktree__is_locked(&reason, wt)) < 0)
578 1 2 if (error) {
579 0 1 if (!reason.size)
604 0 2 GIT_ERROR_CHECK_VERSION(
608 2 0 if (opts)
611 0 2 if (!git_worktree_is_prunable(wt, &popts)) {
617 0 2 if ((err = git_str_join3(&path, '/', wt->commondir_path, "worktrees", wt->name)) < 0)
619 0 2 if (!git_fs_path_exists(path.ptr))
625 0 2 if ((err = git_futils_rmdir_r(path.ptr, NULL, GIT_RMDIR_REMOVE_FILES)) < 0)
636 0 2 if ((wtpath = git_fs_path_dirname(wt->gitlink_path)) == NULL)
639 0 2 if (!git_fs_path_exists(path.ptr))
645 0 2 if ((err = git_futils_rmdir_r(path.ptr, NULL, GIT_RMDIR_REMOVE_FILES)) < 0)