Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
eed378b6
Commit
eed378b6
authored
Jul 20, 2012
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
branch: introduce git_branch_lookup()
parent
b308c11e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
0 deletions
+70
-0
include/git2/branch.h
+24
-0
src/branch.c
+11
-0
tests-clar/refs/branches/lookup.c
+35
-0
No files found.
include/git2/branch.h
View file @
eed378b6
...
...
@@ -117,6 +117,30 @@ GIT_EXTERN(int) git_branch_move(
const
char
*
new_branch_name
,
int
force
);
/**
* Lookup a branch by its name in a repository.
*
* The generated reference must be freed by the user.
*
* @param branch_out pointer to the looked-up branch reference
*
* @param repo the repository to look up the branch
*
* @param branch_name Name of the branch to be looked-up;
* this name is validated for consistency.
*
* @param branch_type Type of the considered branch. This should
* 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.
*/
GIT_EXTERN
(
int
)
git_branch_lookup
(
git_reference
**
branch_out
,
git_repository
*
repo
,
const
char
*
branch_name
,
git_branch_t
branch_type
);
/** @} */
GIT_END_DECL
#endif
src/branch.c
View file @
eed378b6
...
...
@@ -205,3 +205,14 @@ cleanup:
return
error
;
}
int
git_branch_lookup
(
git_reference
**
ref_out
,
git_repository
*
repo
,
const
char
*
branch_name
,
git_branch_t
branch_type
)
{
assert
(
ref_out
&&
repo
&&
branch_name
);
return
retrieve_branch_reference
(
ref_out
,
repo
,
branch_name
,
branch_type
==
GIT_BRANCH_REMOTE
);
}
tests-clar/refs/branches/lookup.c
0 → 100644
View file @
eed378b6
#include "clar_libgit2.h"
#include "refs.h"
static
git_repository
*
repo
;
static
git_reference
*
branch
;
void
test_refs_branches_lookup__initialize
(
void
)
{
cl_git_pass
(
git_repository_open
(
&
repo
,
cl_fixture
(
"testrepo.git"
)));
branch
=
NULL
;
}
void
test_refs_branches_lookup__cleanup
(
void
)
{
git_reference_free
(
branch
);
git_repository_free
(
repo
);
}
void
test_refs_branches_lookup__can_retrieve_a_local_branch
(
void
)
{
cl_git_pass
(
git_branch_lookup
(
&
branch
,
repo
,
"br2"
,
GIT_BRANCH_LOCAL
));
}
void
test_refs_branches_lookup__can_retrieve_a_remote_tracking_branch
(
void
)
{
cl_git_pass
(
git_branch_lookup
(
&
branch
,
repo
,
"test/master"
,
GIT_BRANCH_REMOTE
));
}
void
test_refs_branches_lookup__trying_to_retrieve_an_unknown_branch_returns_ENOTFOUND
(
void
)
{
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
));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment