Commit 88bcd515 by nulltoken

branch: introduce git_reference_is_branch()

parent eed378b6
......@@ -384,6 +384,16 @@ GIT_EXTERN(int) git_reference_remote_tracking_from_branch(
git_reference *branch_ref
);
/**
* Check if a reference is a local branch.
*
* @param ref A git reference
*
* @return 1 when the reference lives in the refs/heads
* namespace; 0 otherwise.
*/
GIT_EXTERN(int) git_reference_is_branch(git_reference *ref);
/** @} */
GIT_END_DECL
#endif
......@@ -1888,3 +1888,10 @@ cleanup:
git_buf_free(&buf);
return error;
}
int git_reference_is_branch(git_reference *ref)
{
assert(ref);
return git__prefixcmp(ref->name, GIT_REFS_HEADS_DIR) == 0;
}
......@@ -202,3 +202,19 @@ void test_refs_read__unfound_return_ENOTFOUND(void)
cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&reference, g_repo, "refs/tags/test/master"));
cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&reference, g_repo, "refs/tags/test/farther/master"));
}
static void assert_is_branch(const char *name, bool expected_branchness)
{
git_reference *reference;
cl_git_pass(git_reference_lookup(&reference, g_repo, name));
cl_assert_equal_i(expected_branchness, git_reference_is_branch(reference));
git_reference_free(reference);
}
void test_refs_read__can_determine_if_a_reference_is_a_local_branch(void)
{
assert_is_branch("refs/heads/master", true);
assert_is_branch("refs/heads/packed", true);
assert_is_branch("refs/remotes/test/master", false);
assert_is_branch("refs/tags/e90810b", false);
}
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