summaryrefslogtreecommitdiff
path: root/src/branch.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2012-08-23 15:47:29 -0700
committerVicent Marti <tanoku@gmail.com>2012-08-26 18:00:10 -0700
commit1c947daa80dfa442acbf8119530a3dcbf5af00c5 (patch)
treebf790b63a2af10cc715d92f202ff7bbe133d071b /src/branch.c
parent17f7bde2f730723f6edae66b454afba481595bb0 (diff)
downloadlibgit2-1c947daa80dfa442acbf8119530a3dcbf5af00c5.tar.gz
branch: Change `git_branch_delete` to take a ref
Diffstat (limited to 'src/branch.c')
-rw-r--r--src/branch.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/branch.c b/src/branch.c
index 52fed67a..da204274 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -50,6 +50,12 @@ static int create_error_invalid(const char *msg)
return -1;
}
+static int not_a_local_branch(git_reference *ref)
+{
+ giterr_set(GITERR_INVALID, "Reference '%s' is not a local branch.", git_reference_name(ref));
+ return -1;
+}
+
int git_branch_create(
git_reference **ref_out,
git_repository *repository,
@@ -106,19 +112,19 @@ cleanup:
return error;
}
-int git_branch_delete(git_repository *repo, const char *branch_name, git_branch_t branch_type)
+int git_branch_delete(git_reference *branch)
{
- git_reference *branch = NULL;
git_reference *head = NULL;
- int error;
- assert(repo && branch_name);
- assert((branch_type == GIT_BRANCH_LOCAL) || (branch_type == GIT_BRANCH_REMOTE));
+ assert(branch);
- if ((error = retrieve_branch_reference(&branch, repo, branch_name, branch_type == GIT_BRANCH_REMOTE)) < 0)
- return error;
+ if (!git_reference_is_branch(branch) &&
+ !git_reference_is_remote(branch)) {
+ giterr_set(GITERR_INVALID, "Reference '%s' is not a valid branch.", git_reference_name(branch));
+ return -1;
+ }
- if (git_reference_lookup(&head, repo, GIT_HEAD_FILE) < 0) {
+ if (git_reference_lookup(&head, git_reference_owner(branch), GIT_HEAD_FILE) < 0) {
giterr_set(GITERR_REFERENCE, "Cannot locate HEAD.");
goto on_error;
}
@@ -126,7 +132,7 @@ int git_branch_delete(git_repository *repo, const char *branch_name, git_branch_
if ((git_reference_type(head) == GIT_REF_SYMBOLIC)
&& (strcmp(git_reference_target(head), git_reference_name(branch)) == 0)) {
giterr_set(GITERR_REFERENCE,
- "Cannot delete branch '%s' as it is the current HEAD of the repository.", branch_name);
+ "Cannot delete branch '%s' as it is the current HEAD of the repository.", git_reference_name(branch));
goto on_error;
}
@@ -138,7 +144,6 @@ int git_branch_delete(git_repository *repo, const char *branch_name, git_branch_
on_error:
git_reference_free(head);
- git_reference_free(branch);
return -1;
}
@@ -185,12 +190,6 @@ int git_branch_foreach(
return git_reference_foreach(repo, GIT_REF_LISTALL, &branch_foreach_cb, (void *)&filter);
}
-static int not_a_local_branch(git_reference *ref)
-{
- giterr_set(GITERR_INVALID, "Reference '%s' is not a local branch.", git_reference_name(ref));
- return -1;
-}
-
int git_branch_move(
git_reference *branch,
const char *new_branch_name,