]> git.proxmox.com Git - libgit2.git/commitdiff
branch: Deploy EINVALIDSPEC usage
authornulltoken <emeric.fermas@gmail.com>
Mon, 12 Nov 2012 19:47:32 +0000 (20:47 +0100)
committernulltoken <emeric.fermas@gmail.com>
Sat, 1 Dec 2012 07:34:28 +0000 (08:34 +0100)
include/git2/branch.h
tests-clar/refs/branches/create.c
tests-clar/refs/branches/lookup.c
tests-clar/refs/branches/move.c

index c9ae9cc5ddcdd9f7439916f9ea2a4367dbe247fc..f55903cd6dd338630f494d6a19f9c3f644b7b0ee 100644 (file)
@@ -29,6 +29,9 @@ GIT_BEGIN_DECL
  *
  * The returned reference must be freed by the user.
  *
+ * The branch name will be checked for validity.
+ * See `git_tag_create()` for rules about valid names.
+ *
  * @param out Pointer where to store the underlying reference.
  *
  * @param branch_name Name for the branch; this name is
@@ -42,7 +45,7 @@ GIT_BEGIN_DECL
  *
  * @param force Overwrite existing branch.
  *
- * @return 0 or an error code.
+ * @return 0, GIT_EINVALIDSPEC or an error code.
  * A proper reference is written in the refs/heads namespace
  * pointing to the provided target commit.
  */
@@ -94,6 +97,9 @@ GIT_EXTERN(int) git_branch_foreach(
 /**
  * Move/rename an existing local branch reference.
  *
+ * The new branch name will be checked for validity.
+ * See `git_tag_create()` for rules about valid names.
+ *
  * @param branch Current underlying reference of the branch.
  *
  * @param new_branch_name Target name of the branch once the move
@@ -101,7 +107,7 @@ GIT_EXTERN(int) git_branch_foreach(
  *
  * @param force Overwrite existing branch.
  *
- * @return 0 on success, or an error code.
+ * @return 0 on success, GIT_EINVALIDSPEC or an error code.
  */
 GIT_EXTERN(int) git_branch_move(
                git_reference *branch,
@@ -113,6 +119,9 @@ GIT_EXTERN(int) git_branch_move(
  *
  * The generated reference must be freed by the user.
  *
+ * The branch name will be checked for validity.
+ * See `git_tag_create()` for rules about valid names.
+ *
  * @param out pointer to the looked-up branch reference
  *
  * @param repo the repository to look up the branch
@@ -124,7 +133,7 @@ GIT_EXTERN(int) git_branch_move(
  * be valued with either GIT_BRANCH_LOCAL or GIT_BRANCH_REMOTE.
  *
  * @return 0 on success; GIT_ENOTFOUND when no matching branch
- * exists, otherwise an error code.
+ * exists, GIT_EINVALIDSPEC, otherwise an error code.
  */
 GIT_EXTERN(int) git_branch_lookup(
                git_reference **out,
index a8c4d4f51fc7fc88ee2345b20947258378f61584..693a592a33ddb2b9cc5536ac7d3be397c93f7c16 100644 (file)
@@ -65,3 +65,12 @@ void test_refs_branches_create__can_force_create_over_an_existing_branch(void)
        cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
        cl_assert_equal_s("refs/heads/br2", git_reference_name(branch));
 }
+
+
+void test_refs_branches_create__creating_a_branch_with_an_invalid_name_returns_EINVALIDSPEC(void)
+{
+       retrieve_known_commit(&target, repo);
+
+       cl_assert_equal_i(GIT_EINVALIDSPEC,
+               git_branch_create(&branch, repo, "inv@{id", target, 0));
+}
\ No newline at end of file
index d07ed0ed808391fa54baae22f7b9082c7a7e2fa6..95d49a4b35c6e30fac06c6b57a9f21635a125042 100644 (file)
@@ -35,3 +35,11 @@ void test_refs_branches_lookup__trying_to_retrieve_an_unknown_branch_returns_ENO
        cl_assert_equal_i(GIT_ENOTFOUND, git_branch_lookup(&branch, repo, "where/are/you", GIT_BRANCH_LOCAL));
        cl_assert_equal_i(GIT_ENOTFOUND, git_branch_lookup(&branch, repo, "over/here", GIT_BRANCH_REMOTE));
 }
+
+void test_refs_branches_lookup__trying_to_retrieve_a_branch_with_an_invalid_name_returns_EINVALIDSPEC(void)
+{
+       cl_assert_equal_i(GIT_EINVALIDSPEC,
+               git_branch_lookup(&branch, repo, "are/you/inv@{id", GIT_BRANCH_LOCAL));
+       cl_assert_equal_i(GIT_EINVALIDSPEC,
+               git_branch_lookup(&branch, repo, "yes/i am", GIT_BRANCH_REMOTE));
+}
index 4bf1d69d0e1bf2a4ee9196e90bd06edcc2b609da..17fb6dfe681eae897dee4a358611f77cf5393c0e 100644 (file)
@@ -51,6 +51,11 @@ void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_coll
        cl_assert_equal_i(GIT_EEXISTS, git_branch_move(ref, "master", 0));
 }
 
+void test_refs_branches_move__moving_a_branch_with_an_invalid_name_returns_EINVALIDSPEC(void)
+{
+       cl_assert_equal_i(GIT_EINVALIDSPEC, git_branch_move(ref, "Inv@{id", 0));
+}
+
 void test_refs_branches_move__can_not_move_a_non_branch(void)
 {
        git_reference *tag;