From 624924e876b9e69ee613dfc38541da3ef0967d56 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Thu, 7 Feb 2013 23:02:56 +0100 Subject: [PATCH 1/3] remote: reorganize tests --- .../createthenload.c} | 6 +- .../network/{remotelocal.c => remote/local.c} | 12 ++-- tests-clar/network/{ => remote}/remotes.c | 58 +++++++++---------- .../{remoterename.c => remote/rename.c} | 26 ++++----- 4 files changed, 51 insertions(+), 51 deletions(-) rename tests-clar/network/{createremotethenload.c => remote/createthenload.c} (83%) rename tests-clar/network/{remotelocal.c => remote/local.c} (84%) rename tests-clar/network/{ => remote}/remotes.c (84%) rename tests-clar/network/{remoterename.c => remote/rename.c} (80%) diff --git a/tests-clar/network/createremotethenload.c b/tests-clar/network/remote/createthenload.c similarity index 83% rename from tests-clar/network/createremotethenload.c rename to tests-clar/network/remote/createthenload.c index b64c2ccc4..ac6cfccd3 100644 --- a/tests-clar/network/createremotethenload.c +++ b/tests-clar/network/remote/createthenload.c @@ -5,7 +5,7 @@ static git_repository *_repo; static git_config *_config; 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"); @@ -19,7 +19,7 @@ void test_network_createremotethenload__initialize(void) 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); _remote = NULL; @@ -30,7 +30,7 @@ void test_network_createremotethenload__cleanup(void) 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_url(_remote), url); diff --git a/tests-clar/network/remotelocal.c b/tests-clar/network/remote/local.c similarity index 84% rename from tests-clar/network/remotelocal.c rename to tests-clar/network/remote/local.c index 5d6a16a2a..db7d8afdd 100644 --- a/tests-clar/network/remotelocal.c +++ b/tests-clar/network/remote/local.c @@ -7,13 +7,13 @@ static git_repository *repo; static git_buf file_path_buf = GIT_BUF_INIT; 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_assert(repo != NULL); } -void test_network_remotelocal__cleanup(void) +void test_network_remote_local__cleanup(void) { git_buf_free(&file_path_buf); @@ -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")); cl_assert(git_remote_connected(remote)); @@ -64,7 +64,7 @@ void test_network_remotelocal__connected(void) 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; @@ -75,7 +75,7 @@ void test_network_remotelocal__retrieve_advertised_references(void) 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; @@ -94,7 +94,7 @@ void test_network_remotelocal__retrieve_advertised_references_from_spaced_reposi 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")); diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remote/remotes.c similarity index 84% rename from tests-clar/network/remotes.c rename to tests-clar/network/remote/remotes.c index 51d6c946f..e68de7f55 100644 --- a/tests-clar/network/remotes.c +++ b/tests-clar/network/remote/remotes.c @@ -7,7 +7,7 @@ static git_remote *_remote; static git_repository *_repo; 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"); @@ -17,7 +17,7 @@ void test_network_remotes__initialize(void) cl_assert(_refspec != NULL); } -void test_network_remotes__cleanup(void) +void test_network_remote_remotes__cleanup(void) { git_remote_free(_remote); _remote = NULL; @@ -25,7 +25,7 @@ void test_network_remotes__cleanup(void) cl_git_sandbox_cleanup(); } -void test_network_remotes__parsing(void) +void test_network_remote_remotes__parsing(void) { git_remote *_remote2 = NULL; @@ -51,7 +51,7 @@ void test_network_remotes__parsing(void) 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_assert_equal_s(git_remote_pushurl(_remote), "git://github.com/libgit2/notlibgit2"); @@ -60,7 +60,7 @@ void test_network_remotes__pushurl(void) 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_transport *t; @@ -82,33 +82,33 @@ void test_network_remotes__error_when_no_push_available(void) 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") ); } -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") ); } -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") ); } -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") ); } -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_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/*")); _refspec = git_remote_fetchspec(_remote); @@ -116,7 +116,7 @@ void test_network_remotes__set_fetchspec(void) 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/*")); _refspec = git_remote_pushspec(_remote); @@ -124,7 +124,7 @@ void test_network_remotes__set_pushspec(void) 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); _remote = NULL; @@ -165,13 +165,13 @@ void test_network_remotes__save(void) 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/multi/level/branch")); } -void test_network_remotes__transform(void) +void test_network_remote_remotes__transform(void) { char ref[1024] = {0}; @@ -179,7 +179,7 @@ void test_network_remotes__transform(void) 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}; @@ -187,7 +187,7 @@ void test_network_remotes__transform_destination_to_source(void) 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; @@ -196,7 +196,7 @@ void test_network_remotes__transform_r(void) git_buf_free(&buf); } -void test_network_remotes__missing_refspecs(void) +void test_network_remote_remotes__missing_refspecs(void) { git_config *cfg; @@ -210,7 +210,7 @@ void test_network_remotes__missing_refspecs(void) git_config_free(cfg); } -void test_network_remotes__list(void) +void test_network_remote_remotes__list(void) { git_strarray list; git_config *cfg; @@ -228,7 +228,7 @@ void test_network_remotes__list(void) 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); _remote = NULL; @@ -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")); } -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); _remote = NULL; @@ -253,7 +253,7 @@ void test_network_remotes__loading_with_an_invalid_name_returns_EINVALIDSPEC(voi * url = http://github.com/libgit2/libgit2 * fetch = +refs/heads/\*:refs/remotes/addtest/\* */ -void test_network_remotes__add(void) +void test_network_remote_remotes__add(void) { git_remote_free(_remote); _remote = NULL; @@ -271,7 +271,7 @@ void test_network_remotes__add(void) 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; @@ -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")); } -void test_network_remotes__cannot_save_an_inmemory_remote(void) +void test_network_remote_remotes__cannot_save_an_inmemory_remote(void) { git_remote *remote; @@ -292,7 +292,7 @@ void test_network_remotes__cannot_save_an_inmemory_remote(void) 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; @@ -307,7 +307,7 @@ void test_network_remotes__cannot_add_a_remote_with_an_invalid_name(void) cl_assert_equal_p(remote, NULL); } -void test_network_remotes__tagopt(void) +void test_network_remote_remotes__tagopt(void) { const char *opt; git_config *cfg; @@ -331,7 +331,7 @@ void test_network_remotes__tagopt(void) 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; @@ -340,7 +340,7 @@ void test_network_remotes__cannot_load_with_an_empty_url(void) 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; const git_error *err; @@ -361,7 +361,7 @@ void test_network_remotes__check_structure_version(void) 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 test_network_remote_remotes__cannot_create_a_remote_which_name_conflicts_with_an_existing_remote(void) { git_remote *remote = NULL; diff --git a/tests-clar/network/remoterename.c b/tests-clar/network/remote/rename.c similarity index 80% rename from tests-clar/network/remoterename.c rename to tests-clar/network/remote/rename.c index 24cfadcc3..ed98ee811 100644 --- a/tests-clar/network/remoterename.c +++ b/tests-clar/network/remote/rename.c @@ -6,14 +6,14 @@ static git_remote *_remote; static git_repository *_repo; -void test_network_remoterename__initialize(void) +void test_network_remote_rename__initialize(void) { _repo = cl_git_sandbox_init("testrepo.git"); 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); _remote = NULL; @@ -31,7 +31,7 @@ static int dont_call_me_cb(const char *fetch_refspec, void *payload) 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.just/renamed.fetch", false); @@ -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); } -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"); @@ -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"); } -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)); 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; @@ -94,7 +94,7 @@ static int ensure_refspecs(const char* refspec_name, void *payload) 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; @@ -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/*"); } -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_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( GIT_EINVALIDSPEC, 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_repository *another_repo; @@ -142,13 +142,13 @@ void test_network_remoterename__renamed_name_is_persisted(void) 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_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; @@ -163,7 +163,7 @@ void test_network_remoterename__renaming_a_remote_moves_the_underlying_reference 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; From 4d811c3b77158fdb7ee50b389c3aa8763482c61a Mon Sep 17 00:00:00 2001 From: nulltoken Date: Thu, 7 Feb 2013 23:40:10 +0100 Subject: [PATCH 2/3] refs: No component of a refname can end with '.lock' --- src/refs.c | 10 ++++++---- tests-clar/refs/isvalidname.c | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/refs.c b/src/refs.c index e75f51001..fd57ce8f7 100644 --- a/src/refs.c +++ b/src/refs.c @@ -1599,6 +1599,7 @@ static int ensure_segment_validity(const char *name) { const char *current = name; char prev = '\0'; + int lock_len = strlen(GIT_FILELOCK_EXTENSION); if (*current == '.') return -1; /* Refname starts with "." */ @@ -1619,6 +1620,11 @@ static int ensure_segment_validity(const char *name) prev = *current; } + /* A refname component can not end with ".lock" */ + if (current - name >= lock_len && + !git__strncmp(current - lock_len, GIT_FILELOCK_EXTENSION, lock_len)) + return -1; + return (int)(current - name); } @@ -1714,10 +1720,6 @@ int git_reference__normalize_name( if (current[segment_len - 1] == '/') 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)) goto cleanup; diff --git a/tests-clar/refs/isvalidname.c b/tests-clar/refs/isvalidname.c index b61a02360..e9fbdbcd1 100644 --- a/tests-clar/refs/isvalidname.c +++ b/tests-clar/refs/isvalidname.c @@ -13,6 +13,7 @@ void test_refs_isvalidname__can_detect_invalid_formats(void) 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("refs/heads/sub.lock/webmatrix")); } void test_refs_isvalidname__wont_hopefully_choke_on_valid_formats(void) From 2bca5b679b9e1f7f7e5cfafa75a6a94549875197 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Thu, 7 Feb 2013 23:44:18 +0100 Subject: [PATCH 3/3] remote: Introduce git_remote_is_valid_name() Fix libgit2/libgit2sharp#318 --- include/git2/remote.h | 8 ++++++ src/refs.c | 9 +++---- src/remote.c | 36 +++++++++++++++---------- tests-clar/network/remote/isvalidname.c | 17 ++++++++++++ tests-clar/network/remote/remotes.c | 22 ++++++++++++--- tests-clar/refs/isvalidname.c | 1 + tests-clar/refs/normalize.c | 2 ++ 7 files changed, 72 insertions(+), 23 deletions(-) create mode 100644 tests-clar/network/remote/isvalidname.c diff --git a/include/git2/remote.h b/include/git2/remote.h index b92a0cd04..6f36a3999 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -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); +/** + * 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 #endif diff --git a/src/refs.c b/src/refs.c index fd57ce8f7..7dabfefae 100644 --- a/src/refs.c +++ b/src/refs.c @@ -1622,7 +1622,7 @@ static int ensure_segment_validity(const char *name) /* A refname component can not end with ".lock" */ if (current - name >= lock_len && - !git__strncmp(current - lock_len, GIT_FILELOCK_EXTENSION, lock_len)) + !memcmp(current - lock_len, GIT_FILELOCK_EXTENSION, lock_len)) return -1; return (int)(current - name); @@ -1697,11 +1697,10 @@ int git_reference__normalize_name( segments_count++; } - /* This means that there's a leading slash in the refname */ - if (segment_len == 0 && segments_count == 0) { + /* No empty segment is allowed when not normalizing */ + if (segment_len == 0 && !normalize) goto cleanup; - } - + if (current[segment_len] == '\0') break; diff --git a/src/remote.c b/src/remote.c index 920ca7a18..0a1f2b856 100644 --- a/src/remote.c +++ b/src/remote.c @@ -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) { - git_buf buf = GIT_BUF_INIT; - git_refspec refspec; - int error = -1; + int error = 0; - 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 (error) { + if (!git_remote_is_valid_name(name)) { giterr_set( GITERR_CONFIG, "'%s' is not a valid remote name.", name); @@ -1380,3 +1368,23 @@ void git_remote_set_update_fetchhead(git_remote *remote, int 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; +} diff --git a/tests-clar/network/remote/isvalidname.c b/tests-clar/network/remote/isvalidname.c new file mode 100644 index 000000000..c26fbd0a5 --- /dev/null +++ b/tests-clar/network/remote/isvalidname.c @@ -0,0 +1,17 @@ +#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")); +} diff --git a/tests-clar/network/remote/remotes.c b/tests-clar/network/remote/remotes.c index e68de7f55..42f090b42 100644 --- a/tests-clar/network/remote/remotes.c +++ b/tests-clar/network/remote/remotes.c @@ -361,13 +361,27 @@ void test_network_remote_remotes__check_structure_version(void) cl_assert_equal_i(GITERR_INVALID, err->klass); } -void test_network_remote_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; - cl_assert_equal_i( - GIT_EEXISTS, - git_remote_create(&remote, _repo, "test", "git://github.com/libgit2/libgit2")); + cl_git_fail_with( + git_remote_create(&remote, _repo, name, "git://github.com/libgit2/libgit2"), + expected_error); 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); +} diff --git a/tests-clar/refs/isvalidname.c b/tests-clar/refs/isvalidname.c index e9fbdbcd1..65c70ba4d 100644 --- a/tests-clar/refs/isvalidname.c +++ b/tests-clar/refs/isvalidname.c @@ -12,6 +12,7 @@ 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("/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("refs/heads/sub.lock/webmatrix")); } diff --git a/tests-clar/refs/normalize.c b/tests-clar/refs/normalize.c index 562c34f06..7f313ef38 100644 --- a/tests-clar/refs/normalize.c +++ b/tests-clar/refs/normalize.c @@ -88,6 +88,8 @@ void test_refs_normalize__symbolic(void) GIT_REF_FORMAT_ALLOW_ONELEVEL, ""); ensure_refname_invalid( GIT_REF_FORMAT_ALLOW_ONELEVEL, "heads\foo"); + ensure_refname_invalid( + GIT_REF_FORMAT_ALLOW_ONELEVEL, "/"); ensure_refname_invalid( GIT_REF_FORMAT_ALLOW_ONELEVEL, "///");