repo_helpers.c 1.02 KB
Newer Older
1 2 3
#include "clar_libgit2.h"
#include "refs.h"
#include "repo_helpers.h"
4
#include "posix.h"
5

6
void make_head_unborn(git_repository* repo, const char *target)
7 8 9
{
	git_reference *head;

10
	cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, target, 1, NULL));
11 12
	git_reference_free(head);
}
13 14 15

void delete_head(git_repository* repo)
{
16
	git_str head_path = GIT_STR_INIT;
17

18 19
	cl_git_pass(git_str_joinpath(&head_path, git_repository_path(repo), GIT_HEAD_FILE));
	cl_git_pass(p_unlink(git_str_cstr(&head_path)));
20

21
	git_str_dispose(&head_path);
22
}
23

24 25
void create_tmp_global_config(const char *dirname, const char *key, const char *val)
{
26
	git_str path = GIT_STR_INIT;
27 28 29 30 31
	git_config *config;

	cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH,
		GIT_CONFIG_LEVEL_GLOBAL, dirname));
	cl_must_pass(p_mkdir(dirname, 0777));
32
	cl_git_pass(git_str_joinpath(&path, dirname, ".gitconfig"));
33 34 35
	cl_git_pass(git_config_open_ondisk(&config, path.ptr));
	cl_git_pass(git_config_set_string(config, key, val));
	git_config_free(config);
36
	git_str_dispose(&path);
37
}