]> git.proxmox.com Git - libgit2.git/blame - tests/repo/repo_helpers.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / repo / repo_helpers.c
CommitLineData
cd1ef822 1#include "clar_libgit2.h"
2#include "refs.h"
3#include "repo_helpers.h"
b1a3a70e 4#include "posix.h"
cd1ef822 5
605da51a 6void make_head_unborn(git_repository* repo, const char *target)
cd1ef822 7{
8 git_reference *head;
9
659cf202 10 cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, target, 1, NULL));
cd1ef822 11 git_reference_free(head);
12}
b1a3a70e 13
14void delete_head(git_repository* repo)
15{
e579e0f7 16 git_str head_path = GIT_STR_INIT;
b1a3a70e 17
e579e0f7
MB
18 cl_git_pass(git_str_joinpath(&head_path, git_repository_path(repo), GIT_HEAD_FILE));
19 cl_git_pass(p_unlink(git_str_cstr(&head_path)));
b1a3a70e 20
e579e0f7 21 git_str_dispose(&head_path);
ac3d33df
JK
22}
23
ac3d33df
JK
24void create_tmp_global_config(const char *dirname, const char *key, const char *val)
25{
e579e0f7 26 git_str path = GIT_STR_INIT;
ac3d33df
JK
27 git_config *config;
28
29 cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH,
30 GIT_CONFIG_LEVEL_GLOBAL, dirname));
31 cl_must_pass(p_mkdir(dirname, 0777));
e579e0f7 32 cl_git_pass(git_str_joinpath(&path, dirname, ".gitconfig"));
ac3d33df
JK
33 cl_git_pass(git_config_open_ondisk(&config, path.ptr));
34 cl_git_pass(git_config_set_string(config, key, val));
35 git_config_free(config);
e579e0f7 36 git_str_dispose(&path);
b1a3a70e 37}