]> git.proxmox.com Git - libgit2.git/blame - tests/t16-remotes.c
Merge pull request #405 from carlosmn/http-ls
[libgit2.git] / tests / t16-remotes.c
CommitLineData
a030ae50
CMN
1/*
2 * This file is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2,
4 * as published by the Free Software Foundation.
5 *
6 * In addition to the permissions in the GNU General Public License,
7 * the authors give you unlimited permission to link the compiled
8 * version of this file into combinations with other programs,
9 * and to distribute those combinations without any restriction
10 * coming from the use of this file. (The General Public License
11 * restrictions do apply in other respects; for example, they cover
12 * modification of the file, and distribution when not linked into
13 * a combined executable.)
14 *
15 * This file is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; see the file COPYING. If not, write to
22 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
24 */
25#include "test_lib.h"
26#include "test_helpers.h"
27
28#include <git2.h>
c498701d 29#include <posix.h>
a030ae50
CMN
30
31BEGIN_TEST(remotes0, "remote parsing works")
32 git_remote *remote;
33 git_repository *repo;
34 git_config *cfg;
f9d4b0c3
CMN
35 char *old_home;
36
e1b86444 37 old_home = p_getenv("HOME");
c498701d 38 p_setenv("HOME", "/dev/null", 1);
a030ae50
CMN
39
40 must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
f9d4b0c3 41 must_pass(git_repository_config(&cfg, repo, NULL));
a030ae50
CMN
42 must_pass(git_remote_get(&remote, cfg, "test"));
43 must_be_true(!strcmp(git_remote_name(remote), "test"));
44 must_be_true(!strcmp(git_remote_url(remote), "git://github.com/libgit2/libgit2"));
45
46 git_remote_free(remote);
47 git_config_free(cfg);
48 git_repository_free(repo);
f9d4b0c3 49
c498701d 50 p_setenv("HOME", old_home, 1);
f9d4b0c3 51 free(old_home);
a030ae50
CMN
52END_TEST
53
73fdf706
CMN
54BEGIN_TEST(refspec0, "remote with refspec works")
55 git_remote *remote;
56 git_repository *repo;
57 git_config *cfg;
58 const git_refspec *refspec = NULL;
f9d4b0c3
CMN
59 char *old_home;
60
e1b86444 61 old_home = p_getenv("HOME");
c498701d 62 p_setenv("HOME", "/dev/null", 1);
73fdf706
CMN
63
64 must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
f9d4b0c3 65 must_pass(git_repository_config(&cfg, repo, NULL));
73fdf706
CMN
66 must_pass(git_remote_get(&remote, cfg, "test"));
67 refspec = git_remote_fetchspec(remote);
68 must_be_true(refspec != NULL);
69 must_be_true(!strcmp(git_refspec_src(refspec), "refs/heads/*"));
70 must_be_true(!strcmp(git_refspec_dst(refspec), "refs/remotes/test/*"));
71 git_remote_free(remote);
72 git_config_free(cfg);
73 git_repository_free(repo);
f9d4b0c3 74
c498701d 75 p_setenv("HOME", old_home, 1);
f9d4b0c3 76 free(old_home);
73fdf706
CMN
77END_TEST
78
fa9dcb7e
CMN
79BEGIN_TEST(refspec1, "remote fnmatch works as expected")
80 git_remote *remote;
81 git_repository *repo;
82 git_config *cfg;
83 const git_refspec *refspec = NULL;
f9d4b0c3
CMN
84 char *old_home;
85
e1b86444 86 old_home = p_getenv("HOME");
c498701d 87 p_setenv("HOME", "/dev/null", 1);
fa9dcb7e
CMN
88
89 must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
f9d4b0c3 90 must_pass(git_repository_config(&cfg, repo, NULL));
fa9dcb7e
CMN
91 must_pass(git_remote_get(&remote, cfg, "test"));
92 refspec = git_remote_fetchspec(remote);
93 must_be_true(refspec != NULL);
94 must_pass(git_refspec_src_match(refspec, "refs/heads/master"));
95 must_pass(git_refspec_src_match(refspec, "refs/heads/multi/level/branch"));
96 git_remote_free(remote);
97 git_config_free(cfg);
98 git_repository_free(repo);
f9d4b0c3 99
c498701d 100 p_setenv("HOME", old_home, 1);
f9d4b0c3 101 free(old_home);
fa9dcb7e
CMN
102END_TEST
103
c5b2622d
CMN
104BEGIN_TEST(refspec2, "refspec transform")
105 git_remote *remote;
106 git_repository *repo;
107 git_config *cfg;
108 const git_refspec *refspec = NULL;
109 char ref[1024] = {0};
f9d4b0c3
CMN
110 char *old_home;
111
e1b86444 112 old_home = p_getenv("HOME");
c498701d 113 p_setenv("HOME", "/dev/null", 1);
c5b2622d
CMN
114
115 must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
f9d4b0c3 116 must_pass(git_repository_config(&cfg, repo, NULL));
c5b2622d
CMN
117 must_pass(git_remote_get(&remote, cfg, "test"));
118 refspec = git_remote_fetchspec(remote);
119 must_be_true(refspec != NULL);
120 must_pass(git_refspec_transform(ref, sizeof(ref), refspec, "refs/heads/master"));
121 must_be_true(!strcmp(ref, "refs/remotes/test/master"));
122 git_remote_free(remote);
123 git_config_free(cfg);
124 git_repository_free(repo);
f9d4b0c3 125
c498701d 126 p_setenv("HOME", old_home, 1);
f9d4b0c3 127 free(old_home);
c5b2622d
CMN
128END_TEST
129
a030ae50 130BEGIN_SUITE(remotes)
73fdf706
CMN
131 ADD_TEST(remotes0)
132 ADD_TEST(refspec0)
fa9dcb7e 133 ADD_TEST(refspec1)
c5b2622d 134 ADD_TEST(refspec2)
a030ae50 135END_SUITE