aboutsummaryrefslogtreecommitdiff
path: root/builtin-branch.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-11-24 23:10:23 -0800
committerJunio C Hamano <junkio@cox.net>2006-11-24 23:10:23 -0800
commit67affd5173da059ca60aab7896985331acacd9b4 (patch)
tree59ba5a6fcf43fa2b4bbf13fabf644086699fc0b6 /builtin-branch.c
parent75e6e2132006770156d9df1881b4114862919c94 (diff)
downloadgit-67affd5173da059ca60aab7896985331acacd9b4.tar.gz
git-67affd5173da059ca60aab7896985331acacd9b4.tar.xz
git-branch -D: make it work even when on a yet-to-be-born branch
This makes "git branch -D other_branch" work even when HEAD points at a yet-to-be-born branch. Earlier, we checked the HEAD ref for the purpose of "subset" check even when the deletion was forced (i.e. not -d but -D). Because of this, you cannot delete a branch even with -D while on a yet-to-be-born branch. With this change, the following sequence that now works: mkdir newdir && cd newdir git init-db git fetch -k $other_repo refs/heads/master:refs/heads/othre # oops, typo git branch other othre git branch -D othre Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'builtin-branch.c')
-rw-r--r--builtin-branch.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/builtin-branch.c b/builtin-branch.c
index 69b7b55d8..3d5cb0e4b 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -38,12 +38,16 @@ static int in_merge_bases(const unsigned char *sha1,
static void delete_branches(int argc, const char **argv, int force)
{
- struct commit *rev, *head_rev;
+ struct commit *rev, *head_rev = head_rev;
unsigned char sha1[20];
char *name;
int i;
- head_rev = lookup_commit_reference(head_sha1);
+ if (!force) {
+ head_rev = lookup_commit_reference(head_sha1);
+ if (!head_rev)
+ die("Couldn't look up commit object for HEAD");
+ }
for (i = 0; i < argc; i++) {
if (!strcmp(head, argv[i]))
die("Cannot delete the branch you are currently on.");
@@ -53,8 +57,8 @@ static void delete_branches(int argc, const char **argv, int force)
die("Branch '%s' not found.", argv[i]);
rev = lookup_commit_reference(sha1);
- if (!rev || !head_rev)
- die("Couldn't look up commit objects.");
+ if (!rev)
+ die("Couldn't look up commit object for '%s'", name);
/* This checks whether the merge bases of branch and
* HEAD contains branch -- which means that the HEAD