git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tg-delete: Handle the case where the branch has been removed already, but the base is still left.
@ 2010-02-28 11:39 Thomas Schwinge
  2010-02-28 14:00 ` Thomas Schwinge
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Schwinge @ 2010-02-28 11:39 UTC (permalink / raw)
  To: u.kleine-koenig; +Cc: git, Thomas Schwinge

A user might have used 'git branch -D B' to remove the branch B, and then
certain TopGit commands complain, because the base of branch B is still there.
---
 README       |    4 ++++
 tg-delete.sh |   15 ++++++++-------
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/README b/README
index 495c70b..fc74ff8 100644
--- a/README
+++ b/README
@@ -244,6 +244,10 @@ tg delete
 	only empty branch (base == head); use '-f' to remove
 	non-empty branch.
 
+	The '-f' option is also useful to force removal of a branch's base, if
+	you used 'git branch -D B' to remove the branch B, and then certain
+	TopGit commands complain, because the base of branch B is still there.
+
 	Currently, this command will _NOT_ remove the branch from
 	the dependency list in other branches. You need to take
 	care of this _manually_. This is even more complicated
diff --git a/tg-delete.sh b/tg-delete.sh
index ab121c2..e1eea17 100644
--- a/tg-delete.sh
+++ b/tg-delete.sh
@@ -3,7 +3,7 @@
 # (c) Petr Baudis <pasky@suse.cz>  2008
 # GPLv2
 
-force= # Whether to delete non-empty branch
+force= # Whether to delete non-empty branch, or branch where only the base is left.
 name=
 
 
@@ -28,21 +28,22 @@ done
 
 [ -n "$name" ] || die "no branch name specified"
 branchrev="$(git rev-parse --verify "$name" 2>/dev/null)" ||
-	die "invalid branch name: $name"
+	if [ -n "$force" ]; then
+		info "invalid branch name: $name; assuming it has been deleted already"
+	else
+		die "invalid branch name: $name"
+	fi
 baserev="$(git rev-parse --verify "refs/top-bases/$name" 2>/dev/null)" ||
 	die "not a TopGit topic branch: $name"
 ! git symbolic-ref HEAD >/dev/null || [ "$(git symbolic-ref HEAD)" != "refs/heads/$name" ] ||
 	die "cannot delete your current branch"
 
-nonempty=
-branch_empty "$name" || nonempty=1
-
-[ -z "$nonempty" ] || [ -n "$force" ] || die "branch is non-empty: $name"
+[ -z "$force" ] && { branch_empty "$name" || die "branch is non-empty: $name"; }
 
 
 ## Wipe out
 
 git update-ref -d "refs/top-bases/$name" "$baserev"
-git update-ref -d "refs/heads/$name" "$branchrev"
+[ -z "$branchrev" ] || git update-ref -d "refs/heads/$name" "$branchrev"
 
 # vim:noet
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] tg-delete: Handle the case where the branch has been removed already, but the base is still left.
  2010-02-28 11:39 [PATCH] tg-delete: Handle the case where the branch has been removed already, but the base is still left Thomas Schwinge
@ 2010-02-28 14:00 ` Thomas Schwinge
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Schwinge @ 2010-02-28 14:00 UTC (permalink / raw)
  To: u.kleine-koenig, u.kleine-koenig; +Cc: Thomas Schwinge, git

A user might have used 'git branch -D B' to remove the branch B, and then
certain TopGit commands complain, because the base of branch B is still there.

Signed-off-by: Thomas Schwinge <thomas@schwinge.name>

---
 README       |    4 ++++
 tg-delete.sh |   15 ++++++++-------
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/README b/README
index 495c70b..fc74ff8 100644
--- a/README
+++ b/README
@@ -244,6 +244,10 @@ tg delete
 	only empty branch (base == head); use '-f' to remove
 	non-empty branch.
 
+	The '-f' option is also useful to force removal of a branch's base, if
+	you used 'git branch -D B' to remove the branch B, and then certain
+	TopGit commands complain, because the base of branch B is still there.
+
 	Currently, this command will _NOT_ remove the branch from
 	the dependency list in other branches. You need to take
 	care of this _manually_. This is even more complicated
diff --git a/tg-delete.sh b/tg-delete.sh
index ab121c2..e1eea17 100644
--- a/tg-delete.sh
+++ b/tg-delete.sh
@@ -3,7 +3,7 @@
 # (c) Petr Baudis <pasky@suse.cz>  2008
 # GPLv2
 
-force= # Whether to delete non-empty branch
+force= # Whether to delete non-empty branch, or branch where only the base is left.
 name=
 
 
@@ -28,21 +28,22 @@ done
 
 [ -n "$name" ] || die "no branch name specified"
 branchrev="$(git rev-parse --verify "$name" 2>/dev/null)" ||
-	die "invalid branch name: $name"
+	if [ -n "$force" ]; then
+		info "invalid branch name: $name; assuming it has been deleted already"
+	else
+		die "invalid branch name: $name"
+	fi
 baserev="$(git rev-parse --verify "refs/top-bases/$name" 2>/dev/null)" ||
 	die "not a TopGit topic branch: $name"
 ! git symbolic-ref HEAD >/dev/null || [ "$(git symbolic-ref HEAD)" != "refs/heads/$name" ] ||
 	die "cannot delete your current branch"
 
-nonempty=
-branch_empty "$name" || nonempty=1
-
-[ -z "$nonempty" ] || [ -n "$force" ] || die "branch is non-empty: $name"
+[ -z "$force" ] && { branch_empty "$name" || die "branch is non-empty: $name"; }
 
 
 ## Wipe out
 
 git update-ref -d "refs/top-bases/$name" "$baserev"
-git update-ref -d "refs/heads/$name" "$branchrev"
+[ -z "$branchrev" ] || git update-ref -d "refs/heads/$name" "$branchrev"
 
 # vim:noet
-- 
tg: (341a371..) t/tg_delete_already_deleted (depends on: master)

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-02-28 14:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-28 11:39 [PATCH] tg-delete: Handle the case where the branch has been removed already, but the base is still left Thomas Schwinge
2010-02-28 14:00 ` Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).