summaryrefslogtreecommitdiff
path: root/tests/repo/repo_helpers.c
blob: 50a201e8623998c730d162f633db124b6187c682 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "clar_libgit2.h"
#include "refs.h"
#include "repo_helpers.h"
#include "posix.h"

void make_head_unborn(git_repository* repo, const char *target)
{
	git_reference *head;

	cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, target, 1, NULL));
	git_reference_free(head);
}

void delete_head(git_repository* repo)
{
	git_buf head_path = GIT_BUF_INIT;

	cl_git_pass(git_buf_joinpath(&head_path, git_repository_path(repo), GIT_HEAD_FILE));
	cl_git_pass(p_unlink(git_buf_cstr(&head_path)));

	git_buf_dispose(&head_path);
}

int filesystem_supports_symlinks(const char *path)
{
	struct stat st;

	if (p_symlink("target", path) < 0 ||
		p_lstat(path, &st) < 0 ||
		!(S_ISLNK(st.st_mode)))
		return 0;

	return 1;
}