Commit 40a60510 by Russell Belfer

Merge pull request #1324 from nulltoken/topic/remote_isvalidname

Topic/remote isvalidname
parents 390a3c81 2bca5b67
...@@ -450,6 +450,14 @@ GIT_EXTERN(int) git_remote_update_fetchhead(git_remote *remote); ...@@ -450,6 +450,14 @@ GIT_EXTERN(int) git_remote_update_fetchhead(git_remote *remote);
*/ */
GIT_EXTERN(void) git_remote_set_update_fetchhead(git_remote *remote, int value); GIT_EXTERN(void) git_remote_set_update_fetchhead(git_remote *remote, int value);
/**
* Ensure the remote name is well-formed.
*
* @param remote_name name to be checked.
* @return 1 if the reference name is acceptable; 0 if it isn't
*/
GIT_EXTERN(int) git_remote_is_valid_name(const char *remote_name);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
#endif #endif
...@@ -1599,6 +1599,7 @@ static int ensure_segment_validity(const char *name) ...@@ -1599,6 +1599,7 @@ static int ensure_segment_validity(const char *name)
{ {
const char *current = name; const char *current = name;
char prev = '\0'; char prev = '\0';
int lock_len = strlen(GIT_FILELOCK_EXTENSION);
if (*current == '.') if (*current == '.')
return -1; /* Refname starts with "." */ return -1; /* Refname starts with "." */
...@@ -1619,6 +1620,11 @@ static int ensure_segment_validity(const char *name) ...@@ -1619,6 +1620,11 @@ static int ensure_segment_validity(const char *name)
prev = *current; prev = *current;
} }
/* A refname component can not end with ".lock" */
if (current - name >= lock_len &&
!memcmp(current - lock_len, GIT_FILELOCK_EXTENSION, lock_len))
return -1;
return (int)(current - name); return (int)(current - name);
} }
...@@ -1691,10 +1697,9 @@ int git_reference__normalize_name( ...@@ -1691,10 +1697,9 @@ int git_reference__normalize_name(
segments_count++; segments_count++;
} }
/* This means that there's a leading slash in the refname */ /* No empty segment is allowed when not normalizing */
if (segment_len == 0 && segments_count == 0) { if (segment_len == 0 && !normalize)
goto cleanup; goto cleanup;
}
if (current[segment_len] == '\0') if (current[segment_len] == '\0')
break; break;
...@@ -1714,10 +1719,6 @@ int git_reference__normalize_name( ...@@ -1714,10 +1719,6 @@ int git_reference__normalize_name(
if (current[segment_len - 1] == '/') if (current[segment_len - 1] == '/')
goto cleanup; goto cleanup;
/* A refname can not end with ".lock" */
if (!git__suffixcmp(name, GIT_FILELOCK_EXTENSION))
goto cleanup;
if ((segments_count == 1 ) && !(flags & GIT_REF_FORMAT_ALLOW_ONELEVEL)) if ((segments_count == 1 ) && !(flags & GIT_REF_FORMAT_ALLOW_ONELEVEL))
goto cleanup; goto cleanup;
......
...@@ -59,21 +59,9 @@ static int download_tags_value(git_remote *remote, git_config *cfg) ...@@ -59,21 +59,9 @@ static int download_tags_value(git_remote *remote, git_config *cfg)
static int ensure_remote_name_is_valid(const char *name) static int ensure_remote_name_is_valid(const char *name)
{ {
git_buf buf = GIT_BUF_INIT; int error = 0;
git_refspec refspec;
int error = -1;
if (!name || *name == '\0')
goto cleanup;
git_buf_printf(&buf, "refs/heads/test:refs/remotes/%s/test", name);
error = git_refspec__parse(&refspec, git_buf_cstr(&buf), true);
git_buf_free(&buf);
git_refspec__free(&refspec);
cleanup: if (!git_remote_is_valid_name(name)) {
if (error) {
giterr_set( giterr_set(
GITERR_CONFIG, GITERR_CONFIG,
"'%s' is not a valid remote name.", name); "'%s' is not a valid remote name.", name);
...@@ -1380,3 +1368,23 @@ void git_remote_set_update_fetchhead(git_remote *remote, int value) ...@@ -1380,3 +1368,23 @@ void git_remote_set_update_fetchhead(git_remote *remote, int value)
{ {
remote->update_fetchhead = value; remote->update_fetchhead = value;
} }
int git_remote_is_valid_name(
const char *remote_name)
{
git_buf buf = GIT_BUF_INIT;
git_refspec refspec;
int error = -1;
if (!remote_name || *remote_name == '\0')
return 0;
git_buf_printf(&buf, "refs/heads/test:refs/remotes/%s/test", remote_name);
error = git_refspec__parse(&refspec, git_buf_cstr(&buf), true);
git_buf_free(&buf);
git_refspec__free(&refspec);
giterr_clear();
return error == 0;
}
...@@ -5,7 +5,7 @@ static git_repository *_repo; ...@@ -5,7 +5,7 @@ static git_repository *_repo;
static git_config *_config; static git_config *_config;
static char url[] = "http://github.com/libgit2/libgit2.git"; static char url[] = "http://github.com/libgit2/libgit2.git";
void test_network_createremotethenload__initialize(void) void test_network_remote_createthenload__initialize(void)
{ {
cl_fixture_sandbox("testrepo.git"); cl_fixture_sandbox("testrepo.git");
...@@ -19,7 +19,7 @@ void test_network_createremotethenload__initialize(void) ...@@ -19,7 +19,7 @@ void test_network_createremotethenload__initialize(void)
cl_git_pass(git_remote_load(&_remote, _repo, "origin")); cl_git_pass(git_remote_load(&_remote, _repo, "origin"));
} }
void test_network_createremotethenload__cleanup(void) void test_network_remote_createthenload__cleanup(void)
{ {
git_remote_free(_remote); git_remote_free(_remote);
_remote = NULL; _remote = NULL;
...@@ -30,7 +30,7 @@ void test_network_createremotethenload__cleanup(void) ...@@ -30,7 +30,7 @@ void test_network_createremotethenload__cleanup(void)
cl_fixture_cleanup("testrepo.git"); cl_fixture_cleanup("testrepo.git");
} }
void test_network_createremotethenload__parsing(void) void test_network_remote_createthenload__parsing(void)
{ {
cl_assert_equal_s(git_remote_name(_remote), "origin"); cl_assert_equal_s(git_remote_name(_remote), "origin");
cl_assert_equal_s(git_remote_url(_remote), url); cl_assert_equal_s(git_remote_url(_remote), url);
......
#include "clar_libgit2.h"
void test_network_remote_isvalidname__can_detect_invalid_formats(void)
{
cl_assert_equal_i(false, git_remote_is_valid_name("/"));
cl_assert_equal_i(false, git_remote_is_valid_name("//"));
cl_assert_equal_i(false, git_remote_is_valid_name(".lock"));
cl_assert_equal_i(false, git_remote_is_valid_name("a.lock"));
cl_assert_equal_i(false, git_remote_is_valid_name("/no/leading/slash"));
cl_assert_equal_i(false, git_remote_is_valid_name("no/trailing/slash/"));
}
void test_network_remote_isvalidname__wont_hopefully_choke_on_valid_formats(void)
{
cl_assert_equal_i(true, git_remote_is_valid_name("webmatrix"));
cl_assert_equal_i(true, git_remote_is_valid_name("yishaigalatzer/rules"));
}
...@@ -7,13 +7,13 @@ static git_repository *repo; ...@@ -7,13 +7,13 @@ static git_repository *repo;
static git_buf file_path_buf = GIT_BUF_INIT; static git_buf file_path_buf = GIT_BUF_INIT;
static git_remote *remote; static git_remote *remote;
void test_network_remotelocal__initialize(void) void test_network_remote_local__initialize(void)
{ {
cl_git_pass(git_repository_init(&repo, "remotelocal/", 0)); cl_git_pass(git_repository_init(&repo, "remotelocal/", 0));
cl_assert(repo != NULL); cl_assert(repo != NULL);
} }
void test_network_remotelocal__cleanup(void) void test_network_remote_local__cleanup(void)
{ {
git_buf_free(&file_path_buf); git_buf_free(&file_path_buf);
...@@ -55,7 +55,7 @@ static void connect_to_local_repository(const char *local_repository) ...@@ -55,7 +55,7 @@ static void connect_to_local_repository(const char *local_repository)
} }
void test_network_remotelocal__connected(void) void test_network_remote_local__connected(void)
{ {
connect_to_local_repository(cl_fixture("testrepo.git")); connect_to_local_repository(cl_fixture("testrepo.git"));
cl_assert(git_remote_connected(remote)); cl_assert(git_remote_connected(remote));
...@@ -64,7 +64,7 @@ void test_network_remotelocal__connected(void) ...@@ -64,7 +64,7 @@ void test_network_remotelocal__connected(void)
cl_assert(!git_remote_connected(remote)); cl_assert(!git_remote_connected(remote));
} }
void test_network_remotelocal__retrieve_advertised_references(void) void test_network_remote_local__retrieve_advertised_references(void)
{ {
int how_many_refs = 0; int how_many_refs = 0;
...@@ -75,7 +75,7 @@ void test_network_remotelocal__retrieve_advertised_references(void) ...@@ -75,7 +75,7 @@ void test_network_remotelocal__retrieve_advertised_references(void)
cl_assert_equal_i(how_many_refs, 26); cl_assert_equal_i(how_many_refs, 26);
} }
void test_network_remotelocal__retrieve_advertised_references_from_spaced_repository(void) void test_network_remote_local__retrieve_advertised_references_from_spaced_repository(void)
{ {
int how_many_refs = 0; int how_many_refs = 0;
...@@ -94,7 +94,7 @@ void test_network_remotelocal__retrieve_advertised_references_from_spaced_reposi ...@@ -94,7 +94,7 @@ void test_network_remotelocal__retrieve_advertised_references_from_spaced_reposi
cl_fixture_cleanup("spaced testrepo.git"); cl_fixture_cleanup("spaced testrepo.git");
} }
void test_network_remotelocal__nested_tags_are_completely_peeled(void) void test_network_remote_local__nested_tags_are_completely_peeled(void)
{ {
connect_to_local_repository(cl_fixture("testrepo.git")); connect_to_local_repository(cl_fixture("testrepo.git"));
......
...@@ -7,7 +7,7 @@ static git_remote *_remote; ...@@ -7,7 +7,7 @@ static git_remote *_remote;
static git_repository *_repo; static git_repository *_repo;
static const git_refspec *_refspec; static const git_refspec *_refspec;
void test_network_remotes__initialize(void) void test_network_remote_remotes__initialize(void)
{ {
_repo = cl_git_sandbox_init("testrepo.git"); _repo = cl_git_sandbox_init("testrepo.git");
...@@ -17,7 +17,7 @@ void test_network_remotes__initialize(void) ...@@ -17,7 +17,7 @@ void test_network_remotes__initialize(void)
cl_assert(_refspec != NULL); cl_assert(_refspec != NULL);
} }
void test_network_remotes__cleanup(void) void test_network_remote_remotes__cleanup(void)
{ {
git_remote_free(_remote); git_remote_free(_remote);
_remote = NULL; _remote = NULL;
...@@ -25,7 +25,7 @@ void test_network_remotes__cleanup(void) ...@@ -25,7 +25,7 @@ void test_network_remotes__cleanup(void)
cl_git_sandbox_cleanup(); cl_git_sandbox_cleanup();
} }
void test_network_remotes__parsing(void) void test_network_remote_remotes__parsing(void)
{ {
git_remote *_remote2 = NULL; git_remote *_remote2 = NULL;
...@@ -51,7 +51,7 @@ void test_network_remotes__parsing(void) ...@@ -51,7 +51,7 @@ void test_network_remotes__parsing(void)
git_remote_free(_remote2); git_remote_free(_remote2);
} }
void test_network_remotes__pushurl(void) void test_network_remote_remotes__pushurl(void)
{ {
cl_git_pass(git_remote_set_pushurl(_remote, "git://github.com/libgit2/notlibgit2")); cl_git_pass(git_remote_set_pushurl(_remote, "git://github.com/libgit2/notlibgit2"));
cl_assert_equal_s(git_remote_pushurl(_remote), "git://github.com/libgit2/notlibgit2"); cl_assert_equal_s(git_remote_pushurl(_remote), "git://github.com/libgit2/notlibgit2");
...@@ -60,7 +60,7 @@ void test_network_remotes__pushurl(void) ...@@ -60,7 +60,7 @@ void test_network_remotes__pushurl(void)
cl_assert(git_remote_pushurl(_remote) == NULL); cl_assert(git_remote_pushurl(_remote) == NULL);
} }
void test_network_remotes__error_when_no_push_available(void) void test_network_remote_remotes__error_when_no_push_available(void)
{ {
git_remote *r; git_remote *r;
git_transport *t; git_transport *t;
...@@ -82,33 +82,33 @@ void test_network_remotes__error_when_no_push_available(void) ...@@ -82,33 +82,33 @@ void test_network_remotes__error_when_no_push_available(void)
git_remote_free(r); git_remote_free(r);
} }
void test_network_remotes__parsing_ssh_remote(void) void test_network_remote_remotes__parsing_ssh_remote(void)
{ {
cl_assert( git_remote_valid_url("git@github.com:libgit2/libgit2.git") ); cl_assert( git_remote_valid_url("git@github.com:libgit2/libgit2.git") );
} }
void test_network_remotes__parsing_local_path_fails_if_path_not_found(void) void test_network_remote_remotes__parsing_local_path_fails_if_path_not_found(void)
{ {
cl_assert( !git_remote_valid_url("/home/git/repos/libgit2.git") ); cl_assert( !git_remote_valid_url("/home/git/repos/libgit2.git") );
} }
void test_network_remotes__supported_transport_methods_are_supported(void) void test_network_remote_remotes__supported_transport_methods_are_supported(void)
{ {
cl_assert( git_remote_supported_url("git://github.com/libgit2/libgit2") ); cl_assert( git_remote_supported_url("git://github.com/libgit2/libgit2") );
} }
void test_network_remotes__unsupported_transport_methods_are_unsupported(void) void test_network_remote_remotes__unsupported_transport_methods_are_unsupported(void)
{ {
cl_assert( !git_remote_supported_url("git@github.com:libgit2/libgit2.git") ); cl_assert( !git_remote_supported_url("git@github.com:libgit2/libgit2.git") );
} }
void test_network_remotes__refspec_parsing(void) void test_network_remote_remotes__refspec_parsing(void)
{ {
cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*"); cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*");
cl_assert_equal_s(git_refspec_dst(_refspec), "refs/remotes/test/*"); cl_assert_equal_s(git_refspec_dst(_refspec), "refs/remotes/test/*");
} }
void test_network_remotes__set_fetchspec(void) void test_network_remote_remotes__set_fetchspec(void)
{ {
cl_git_pass(git_remote_set_fetchspec(_remote, "refs/*:refs/*")); cl_git_pass(git_remote_set_fetchspec(_remote, "refs/*:refs/*"));
_refspec = git_remote_fetchspec(_remote); _refspec = git_remote_fetchspec(_remote);
...@@ -116,7 +116,7 @@ void test_network_remotes__set_fetchspec(void) ...@@ -116,7 +116,7 @@ void test_network_remotes__set_fetchspec(void)
cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*"); cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*");
} }
void test_network_remotes__set_pushspec(void) void test_network_remote_remotes__set_pushspec(void)
{ {
cl_git_pass(git_remote_set_pushspec(_remote, "refs/*:refs/*")); cl_git_pass(git_remote_set_pushspec(_remote, "refs/*:refs/*"));
_refspec = git_remote_pushspec(_remote); _refspec = git_remote_pushspec(_remote);
...@@ -124,7 +124,7 @@ void test_network_remotes__set_pushspec(void) ...@@ -124,7 +124,7 @@ void test_network_remotes__set_pushspec(void)
cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*"); cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*");
} }
void test_network_remotes__save(void) void test_network_remote_remotes__save(void)
{ {
git_remote_free(_remote); git_remote_free(_remote);
_remote = NULL; _remote = NULL;
...@@ -165,13 +165,13 @@ void test_network_remotes__save(void) ...@@ -165,13 +165,13 @@ void test_network_remotes__save(void)
cl_assert(git_remote_pushurl(_remote) == NULL); cl_assert(git_remote_pushurl(_remote) == NULL);
} }
void test_network_remotes__fnmatch(void) void test_network_remote_remotes__fnmatch(void)
{ {
cl_assert(git_refspec_src_matches(_refspec, "refs/heads/master")); cl_assert(git_refspec_src_matches(_refspec, "refs/heads/master"));
cl_assert(git_refspec_src_matches(_refspec, "refs/heads/multi/level/branch")); cl_assert(git_refspec_src_matches(_refspec, "refs/heads/multi/level/branch"));
} }
void test_network_remotes__transform(void) void test_network_remote_remotes__transform(void)
{ {
char ref[1024] = {0}; char ref[1024] = {0};
...@@ -179,7 +179,7 @@ void test_network_remotes__transform(void) ...@@ -179,7 +179,7 @@ void test_network_remotes__transform(void)
cl_assert_equal_s(ref, "refs/remotes/test/master"); cl_assert_equal_s(ref, "refs/remotes/test/master");
} }
void test_network_remotes__transform_destination_to_source(void) void test_network_remote_remotes__transform_destination_to_source(void)
{ {
char ref[1024] = {0}; char ref[1024] = {0};
...@@ -187,7 +187,7 @@ void test_network_remotes__transform_destination_to_source(void) ...@@ -187,7 +187,7 @@ void test_network_remotes__transform_destination_to_source(void)
cl_assert_equal_s(ref, "refs/heads/master"); cl_assert_equal_s(ref, "refs/heads/master");
} }
void test_network_remotes__transform_r(void) void test_network_remote_remotes__transform_r(void)
{ {
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
...@@ -196,7 +196,7 @@ void test_network_remotes__transform_r(void) ...@@ -196,7 +196,7 @@ void test_network_remotes__transform_r(void)
git_buf_free(&buf); git_buf_free(&buf);
} }
void test_network_remotes__missing_refspecs(void) void test_network_remote_remotes__missing_refspecs(void)
{ {
git_config *cfg; git_config *cfg;
...@@ -210,7 +210,7 @@ void test_network_remotes__missing_refspecs(void) ...@@ -210,7 +210,7 @@ void test_network_remotes__missing_refspecs(void)
git_config_free(cfg); git_config_free(cfg);
} }
void test_network_remotes__list(void) void test_network_remote_remotes__list(void)
{ {
git_strarray list; git_strarray list;
git_config *cfg; git_config *cfg;
...@@ -228,7 +228,7 @@ void test_network_remotes__list(void) ...@@ -228,7 +228,7 @@ void test_network_remotes__list(void)
git_config_free(cfg); git_config_free(cfg);
} }
void test_network_remotes__loading_a_missing_remote_returns_ENOTFOUND(void) void test_network_remote_remotes__loading_a_missing_remote_returns_ENOTFOUND(void)
{ {
git_remote_free(_remote); git_remote_free(_remote);
_remote = NULL; _remote = NULL;
...@@ -236,7 +236,7 @@ void test_network_remotes__loading_a_missing_remote_returns_ENOTFOUND(void) ...@@ -236,7 +236,7 @@ void test_network_remotes__loading_a_missing_remote_returns_ENOTFOUND(void)
cl_assert_equal_i(GIT_ENOTFOUND, git_remote_load(&_remote, _repo, "just-left-few-minutes-ago")); cl_assert_equal_i(GIT_ENOTFOUND, git_remote_load(&_remote, _repo, "just-left-few-minutes-ago"));
} }
void test_network_remotes__loading_with_an_invalid_name_returns_EINVALIDSPEC(void) void test_network_remote_remotes__loading_with_an_invalid_name_returns_EINVALIDSPEC(void)
{ {
git_remote_free(_remote); git_remote_free(_remote);
_remote = NULL; _remote = NULL;
...@@ -253,7 +253,7 @@ void test_network_remotes__loading_with_an_invalid_name_returns_EINVALIDSPEC(voi ...@@ -253,7 +253,7 @@ void test_network_remotes__loading_with_an_invalid_name_returns_EINVALIDSPEC(voi
* url = http://github.com/libgit2/libgit2 * url = http://github.com/libgit2/libgit2
* fetch = +refs/heads/\*:refs/remotes/addtest/\* * fetch = +refs/heads/\*:refs/remotes/addtest/\*
*/ */
void test_network_remotes__add(void) void test_network_remote_remotes__add(void)
{ {
git_remote_free(_remote); git_remote_free(_remote);
_remote = NULL; _remote = NULL;
...@@ -271,7 +271,7 @@ void test_network_remotes__add(void) ...@@ -271,7 +271,7 @@ void test_network_remotes__add(void)
cl_assert_equal_s(git_remote_url(_remote), "http://github.com/libgit2/libgit2"); cl_assert_equal_s(git_remote_url(_remote), "http://github.com/libgit2/libgit2");
} }
void test_network_remotes__cannot_add_a_nameless_remote(void) void test_network_remote_remotes__cannot_add_a_nameless_remote(void)
{ {
git_remote *remote; git_remote *remote;
...@@ -280,7 +280,7 @@ void test_network_remotes__cannot_add_a_nameless_remote(void) ...@@ -280,7 +280,7 @@ void test_network_remotes__cannot_add_a_nameless_remote(void)
git_remote_create(&remote, _repo, NULL, "git://github.com/libgit2/libgit2")); git_remote_create(&remote, _repo, NULL, "git://github.com/libgit2/libgit2"));
} }
void test_network_remotes__cannot_save_an_inmemory_remote(void) void test_network_remote_remotes__cannot_save_an_inmemory_remote(void)
{ {
git_remote *remote; git_remote *remote;
...@@ -292,7 +292,7 @@ void test_network_remotes__cannot_save_an_inmemory_remote(void) ...@@ -292,7 +292,7 @@ void test_network_remotes__cannot_save_an_inmemory_remote(void)
git_remote_free(remote); git_remote_free(remote);
} }
void test_network_remotes__cannot_add_a_remote_with_an_invalid_name(void) void test_network_remote_remotes__cannot_add_a_remote_with_an_invalid_name(void)
{ {
git_remote *remote = NULL; git_remote *remote = NULL;
...@@ -307,7 +307,7 @@ void test_network_remotes__cannot_add_a_remote_with_an_invalid_name(void) ...@@ -307,7 +307,7 @@ void test_network_remotes__cannot_add_a_remote_with_an_invalid_name(void)
cl_assert_equal_p(remote, NULL); cl_assert_equal_p(remote, NULL);
} }
void test_network_remotes__tagopt(void) void test_network_remote_remotes__tagopt(void)
{ {
const char *opt; const char *opt;
git_config *cfg; git_config *cfg;
...@@ -331,7 +331,7 @@ void test_network_remotes__tagopt(void) ...@@ -331,7 +331,7 @@ void test_network_remotes__tagopt(void)
git_config_free(cfg); git_config_free(cfg);
} }
void test_network_remotes__cannot_load_with_an_empty_url(void) void test_network_remote_remotes__cannot_load_with_an_empty_url(void)
{ {
git_remote *remote = NULL; git_remote *remote = NULL;
...@@ -340,7 +340,7 @@ void test_network_remotes__cannot_load_with_an_empty_url(void) ...@@ -340,7 +340,7 @@ void test_network_remotes__cannot_load_with_an_empty_url(void)
cl_assert_equal_p(remote, NULL); cl_assert_equal_p(remote, NULL);
} }
void test_network_remotes__check_structure_version(void) void test_network_remote_remotes__check_structure_version(void)
{ {
git_transport transport = GIT_TRANSPORT_INIT; git_transport transport = GIT_TRANSPORT_INIT;
const git_error *err; const git_error *err;
...@@ -361,13 +361,27 @@ void test_network_remotes__check_structure_version(void) ...@@ -361,13 +361,27 @@ void test_network_remotes__check_structure_version(void)
cl_assert_equal_i(GITERR_INVALID, err->klass); cl_assert_equal_i(GITERR_INVALID, err->klass);
} }
void test_network_remotes__cannot_create_a_remote_which_name_conflicts_with_an_existing_remote(void) void assert_cannot_create_remote(const char *name, int expected_error)
{ {
git_remote *remote = NULL; git_remote *remote = NULL;
cl_assert_equal_i( cl_git_fail_with(
GIT_EEXISTS, git_remote_create(&remote, _repo, name, "git://github.com/libgit2/libgit2"),
git_remote_create(&remote, _repo, "test", "git://github.com/libgit2/libgit2")); expected_error);
cl_assert_equal_p(remote, NULL); cl_assert_equal_p(remote, NULL);
} }
void test_network_remote_remotes__cannot_create_a_remote_which_name_conflicts_with_an_existing_remote(void)
{
assert_cannot_create_remote("test", GIT_EEXISTS);
}
void test_network_remote_remotes__cannot_create_a_remote_which_name_is_invalid(void)
{
assert_cannot_create_remote("/", GIT_EINVALIDSPEC);
assert_cannot_create_remote("//", GIT_EINVALIDSPEC);
assert_cannot_create_remote(".lock", GIT_EINVALIDSPEC);
assert_cannot_create_remote("a.lock", GIT_EINVALIDSPEC);
}
...@@ -6,14 +6,14 @@ ...@@ -6,14 +6,14 @@
static git_remote *_remote; static git_remote *_remote;
static git_repository *_repo; static git_repository *_repo;
void test_network_remoterename__initialize(void) void test_network_remote_rename__initialize(void)
{ {
_repo = cl_git_sandbox_init("testrepo.git"); _repo = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_remote_load(&_remote, _repo, "test")); cl_git_pass(git_remote_load(&_remote, _repo, "test"));
} }
void test_network_remoterename__cleanup(void) void test_network_remote_rename__cleanup(void)
{ {
git_remote_free(_remote); git_remote_free(_remote);
_remote = NULL; _remote = NULL;
...@@ -31,7 +31,7 @@ static int dont_call_me_cb(const char *fetch_refspec, void *payload) ...@@ -31,7 +31,7 @@ static int dont_call_me_cb(const char *fetch_refspec, void *payload)
return -1; return -1;
} }
void test_network_remoterename__renaming_a_remote_moves_related_configuration_section(void) void test_network_remote_rename__renaming_a_remote_moves_related_configuration_section(void)
{ {
assert_config_entry_existence(_repo, "remote.test.fetch", true); assert_config_entry_existence(_repo, "remote.test.fetch", true);
assert_config_entry_existence(_repo, "remote.just/renamed.fetch", false); assert_config_entry_existence(_repo, "remote.just/renamed.fetch", false);
...@@ -42,7 +42,7 @@ void test_network_remoterename__renaming_a_remote_moves_related_configuration_se ...@@ -42,7 +42,7 @@ void test_network_remoterename__renaming_a_remote_moves_related_configuration_se
assert_config_entry_existence(_repo, "remote.just/renamed.fetch", true); assert_config_entry_existence(_repo, "remote.just/renamed.fetch", true);
} }
void test_network_remoterename__renaming_a_remote_updates_branch_related_configuration_entries(void) void test_network_remote_rename__renaming_a_remote_updates_branch_related_configuration_entries(void)
{ {
assert_config_entry_value(_repo, "branch.master.remote", "test"); assert_config_entry_value(_repo, "branch.master.remote", "test");
...@@ -51,14 +51,14 @@ void test_network_remoterename__renaming_a_remote_updates_branch_related_configu ...@@ -51,14 +51,14 @@ void test_network_remoterename__renaming_a_remote_updates_branch_related_configu
assert_config_entry_value(_repo, "branch.master.remote", "just/renamed"); assert_config_entry_value(_repo, "branch.master.remote", "just/renamed");
} }
void test_network_remoterename__renaming_a_remote_updates_default_fetchrefspec(void) void test_network_remote_rename__renaming_a_remote_updates_default_fetchrefspec(void)
{ {
cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL)); cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL));
assert_config_entry_value(_repo, "remote.just/renamed.fetch", "+refs/heads/*:refs/remotes/just/renamed/*"); assert_config_entry_value(_repo, "remote.just/renamed.fetch", "+refs/heads/*:refs/remotes/just/renamed/*");
} }
void test_network_remoterename__renaming_a_remote_without_a_fetchrefspec_doesnt_create_one(void) void test_network_remote_rename__renaming_a_remote_without_a_fetchrefspec_doesnt_create_one(void)
{ {
git_config *config; git_config *config;
...@@ -94,7 +94,7 @@ static int ensure_refspecs(const char* refspec_name, void *payload) ...@@ -94,7 +94,7 @@ static int ensure_refspecs(const char* refspec_name, void *payload)
return 0; return 0;
} }
void test_network_remoterename__renaming_a_remote_notifies_of_non_default_fetchrefspec(void) void test_network_remote_rename__renaming_a_remote_notifies_of_non_default_fetchrefspec(void)
{ {
git_config *config; git_config *config;
...@@ -113,20 +113,20 @@ void test_network_remoterename__renaming_a_remote_notifies_of_non_default_fetchr ...@@ -113,20 +113,20 @@ void test_network_remoterename__renaming_a_remote_notifies_of_non_default_fetchr
assert_config_entry_value(_repo, "remote.just/renamed.fetch", "+refs/*:refs/*"); assert_config_entry_value(_repo, "remote.just/renamed.fetch", "+refs/*:refs/*");
} }
void test_network_remoterename__new_name_can_contain_dots(void) void test_network_remote_rename__new_name_can_contain_dots(void)
{ {
cl_git_pass(git_remote_rename(_remote, "just.renamed", dont_call_me_cb, NULL)); cl_git_pass(git_remote_rename(_remote, "just.renamed", dont_call_me_cb, NULL));
cl_assert_equal_s("just.renamed", git_remote_name(_remote)); cl_assert_equal_s("just.renamed", git_remote_name(_remote));
} }
void test_network_remoterename__new_name_must_conform_to_reference_naming_conventions(void) void test_network_remote_rename__new_name_must_conform_to_reference_naming_conventions(void)
{ {
cl_assert_equal_i( cl_assert_equal_i(
GIT_EINVALIDSPEC, GIT_EINVALIDSPEC,
git_remote_rename(_remote, "new@{name", dont_call_me_cb, NULL)); git_remote_rename(_remote, "new@{name", dont_call_me_cb, NULL));
} }
void test_network_remoterename__renamed_name_is_persisted(void) void test_network_remote_rename__renamed_name_is_persisted(void)
{ {
git_remote *renamed; git_remote *renamed;
git_repository *another_repo; git_repository *another_repo;
...@@ -142,13 +142,13 @@ void test_network_remoterename__renamed_name_is_persisted(void) ...@@ -142,13 +142,13 @@ void test_network_remoterename__renamed_name_is_persisted(void)
git_repository_free(another_repo); git_repository_free(another_repo);
} }
void test_network_remoterename__cannot_overwrite_an_existing_remote(void) void test_network_remote_rename__cannot_overwrite_an_existing_remote(void)
{ {
cl_assert_equal_i(GIT_EEXISTS, git_remote_rename(_remote, "test", dont_call_me_cb, NULL)); cl_assert_equal_i(GIT_EEXISTS, git_remote_rename(_remote, "test", dont_call_me_cb, NULL));
cl_assert_equal_i(GIT_EEXISTS, git_remote_rename(_remote, "test_with_pushurl", dont_call_me_cb, NULL)); cl_assert_equal_i(GIT_EEXISTS, git_remote_rename(_remote, "test_with_pushurl", dont_call_me_cb, NULL));
} }
void test_network_remoterename__renaming_a_remote_moves_the_underlying_reference(void) void test_network_remote_rename__renaming_a_remote_moves_the_underlying_reference(void)
{ {
git_reference *underlying; git_reference *underlying;
...@@ -163,7 +163,7 @@ void test_network_remoterename__renaming_a_remote_moves_the_underlying_reference ...@@ -163,7 +163,7 @@ void test_network_remoterename__renaming_a_remote_moves_the_underlying_reference
git_reference_free(underlying); git_reference_free(underlying);
} }
void test_network_remoterename__cannot_rename_an_inmemory_remote(void) void test_network_remote_rename__cannot_rename_an_inmemory_remote(void)
{ {
git_remote *remote; git_remote *remote;
......
...@@ -12,7 +12,9 @@ void test_refs_isvalidname__can_detect_invalid_formats(void) ...@@ -12,7 +12,9 @@ void test_refs_isvalidname__can_detect_invalid_formats(void)
cl_assert_equal_i(false, git_reference_is_valid_name("lower_case")); cl_assert_equal_i(false, git_reference_is_valid_name("lower_case"));
cl_assert_equal_i(false, git_reference_is_valid_name("/stupid/name/master")); cl_assert_equal_i(false, git_reference_is_valid_name("/stupid/name/master"));
cl_assert_equal_i(false, git_reference_is_valid_name("/")); cl_assert_equal_i(false, git_reference_is_valid_name("/"));
cl_assert_equal_i(false, git_reference_is_valid_name("//"));
cl_assert_equal_i(false, git_reference_is_valid_name("")); cl_assert_equal_i(false, git_reference_is_valid_name(""));
cl_assert_equal_i(false, git_reference_is_valid_name("refs/heads/sub.lock/webmatrix"));
} }
void test_refs_isvalidname__wont_hopefully_choke_on_valid_formats(void) void test_refs_isvalidname__wont_hopefully_choke_on_valid_formats(void)
......
...@@ -89,6 +89,8 @@ void test_refs_normalize__symbolic(void) ...@@ -89,6 +89,8 @@ void test_refs_normalize__symbolic(void)
ensure_refname_invalid( ensure_refname_invalid(
GIT_REF_FORMAT_ALLOW_ONELEVEL, "heads\foo"); GIT_REF_FORMAT_ALLOW_ONELEVEL, "heads\foo");
ensure_refname_invalid( ensure_refname_invalid(
GIT_REF_FORMAT_ALLOW_ONELEVEL, "/");
ensure_refname_invalid(
GIT_REF_FORMAT_ALLOW_ONELEVEL, "///"); GIT_REF_FORMAT_ALLOW_ONELEVEL, "///");
ensure_refname_normalized( ensure_refname_normalized(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment