]> git.proxmox.com Git - libgit2.git/blame - tests/checkout/head.c
git_checkout_opts -> git_checkout_options
[libgit2.git] / tests / checkout / head.c
CommitLineData
8b05bea8 1#include "clar_libgit2.h"
2#include "refs.h"
cd1ef822 3#include "repo/repo_helpers.h"
d8889d2b
RB
4#include "path.h"
5#include "fileops.h"
8b05bea8 6
7static git_repository *g_repo;
8
9void test_checkout_head__initialize(void)
10{
11 g_repo = cl_git_sandbox_init("testrepo");
12}
13
14void test_checkout_head__cleanup(void)
15{
16 cl_git_sandbox_cleanup();
17}
18
605da51a 19void test_checkout_head__unborn_head_returns_GIT_EUNBORNBRANCH(void)
8b05bea8 20{
605da51a 21 make_head_unborn(g_repo, NON_EXISTING_HEAD);
8b05bea8 22
605da51a 23 cl_assert_equal_i(GIT_EUNBORNBRANCH, git_checkout_head(g_repo, NULL));
8b05bea8 24}
d8889d2b
RB
25
26void test_checkout_head__with_index_only_tree(void)
27{
6affd71f 28 git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
d8889d2b
RB
29 git_index *index;
30
31 /* let's start by getting things into a known state */
32
33 opts.checkout_strategy = GIT_CHECKOUT_FORCE;
34 cl_git_pass(git_checkout_head(g_repo, &opts));
35
36 /* now let's stage some new stuff including a new directory */
37
38 cl_git_pass(git_repository_index(&index, g_repo));
39
40 p_mkdir("testrepo/newdir", 0777);
41 cl_git_mkfile("testrepo/newdir/newfile.txt", "new file\n");
42
25743bd7 43 cl_git_pass(git_index_add_bypath(index, "newdir/newfile.txt"));
d8889d2b
RB
44 cl_git_pass(git_index_write(index));
45
46 cl_assert(git_path_isfile("testrepo/newdir/newfile.txt"));
47 cl_assert(git_index_get_bypath(index, "newdir/newfile.txt", 0) != NULL);
48
49 git_index_free(index);
50
51 /* okay, so now we have staged this new file; let's see if we can remove */
52
53 opts.checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED;
54 cl_git_pass(git_checkout_head(g_repo, &opts));
55
56 cl_git_pass(git_repository_index(&index, g_repo));
d8889d2b
RB
57
58 cl_assert(!git_path_isfile("testrepo/newdir/newfile.txt"));
59 cl_assert(git_index_get_bypath(index, "newdir/newfile.txt", 0) == NULL);
60
61 git_index_free(index);
62}