summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2013-01-24 20:45:00 -0800
committerVicent Martí <vicent@github.com>2013-01-24 20:45:00 -0800
commitc9e9640356f4c56fdb86d3313a5a7dcf282b7391 (patch)
tree937977952cb53a57ff773597e8b47dac9edcbd48 /src
parent5425097f0368c43e72210c33b844cf7350843c37 (diff)
parentc253056d2429ea0a6201be60921dbac69dbcc98a (diff)
downloadlibgit2-c9e9640356f4c56fdb86d3313a5a7dcf282b7391.tar.gz
Merge pull request #1277 from sba1/branch-name
Add git_branch_name()
Diffstat (limited to 'src')
-rw-r--r--src/branch.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/branch.c b/src/branch.c
index 65c02b8af..3959409c5 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -221,6 +221,27 @@ int git_branch_lookup(
return retrieve_branch_reference(ref_out, repo, branch_name, branch_type == GIT_BRANCH_REMOTE);
}
+int git_branch_name(const char **out, git_reference *ref)
+{
+ const char *branch_name;
+
+ assert(out && ref);
+
+ branch_name = ref->name;
+
+ if (git_reference_is_branch(ref)) {
+ branch_name += strlen(GIT_REFS_HEADS_DIR);
+ } else if (git_reference_is_remote(ref)) {
+ branch_name += strlen(GIT_REFS_REMOTES_DIR);
+ } else {
+ giterr_set(GITERR_INVALID,
+ "Reference '%s' is neither a local nor a remote branch.", ref->name);
+ return -1;
+ }
+ *out = branch_name;
+ return 0;
+}
+
static int retrieve_tracking_configuration(
const char **out,
git_repository *repo,