{"thread":{"id":"22854","subject":"[PATCH] tg-delete: Handle the case where the branch has been removed already, but the base is still left.","startedAt":"2010-02-28T11:39:34Z","lastAt":"2010-02-28T14:00:39Z","messageCount":2,"participants":["Thomas Schwinge"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"135872","messageId":"1267357174-21417-1-git-send-email-thomas@schwinge.name","threadId":"22854","inReplyTo":null,"subject":"[PATCH] tg-delete: Handle the case where the branch has been removed already, but the base is still left.","fromName":"Thomas Schwinge","fromEmail":"thomas@schwinge.name","sentAt":"2010-02-28T11:39:34Z","receivedAt":"2010-02-28T11:39:34Z","isPatch":true,"sender":{"key":"thomas@schwinge.name","avatar":"https://gravatar.com/avatar/52ddb7ca4856f40a2eb23eac2f499178ff17dcc372d055c6c41ab2ecc4d19ae8?d=mp&s=160"},"body":"A user might have used 'git branch -D B' to remove the branch B, and then\ncertain TopGit commands complain, because the base of branch B is still there.\n---\n README       |    4 ++++\n tg-delete.sh |   15 ++++++++-------\n 2 files changed, 12 insertions(+), 7 deletions(-)\n\ndiff --git a/README b/README\nindex 495c70b..fc74ff8 100644\n--- a/README\n+++ b/README\n@@ -244,6 +244,10 @@ tg delete\n \tonly empty branch (base == head); use '-f' to remove\n \tnon-empty branch.\n \n+\tThe '-f' option is also useful to force removal of a branch's base, if\n+\tyou used 'git branch -D B' to remove the branch B, and then certain\n+\tTopGit commands complain, because the base of branch B is still there.\n+\n \tCurrently, this command will _NOT_ remove the branch from\n \tthe dependency list in other branches. You need to take\n \tcare of this _manually_. This is even more complicated\ndiff --git a/tg-delete.sh b/tg-delete.sh\nindex ab121c2..e1eea17 100644\n--- a/tg-delete.sh\n+++ b/tg-delete.sh\n@@ -3,7 +3,7 @@\n # (c) Petr Baudis <pasky@suse.cz>  2008\n # GPLv2\n \n-force= # Whether to delete non-empty branch\n+force= # Whether to delete non-empty branch, or branch where only the base is left.\n name=\n \n \n@@ -28,21 +28,22 @@ done\n \n [ -n \"$name\" ] || die \"no branch name specified\"\n branchrev=\"$(git rev-parse --verify \"$name\" 2>/dev/null)\" ||\n-\tdie \"invalid branch name: $name\"\n+\tif [ -n \"$force\" ]; then\n+\t\tinfo \"invalid branch name: $name; assuming it has been deleted already\"\n+\telse\n+\t\tdie \"invalid branch name: $name\"\n+\tfi\n baserev=\"$(git rev-parse --verify \"refs/top-bases/$name\" 2>/dev/null)\" ||\n \tdie \"not a TopGit topic branch: $name\"\n ! git symbolic-ref HEAD >/dev/null || [ \"$(git symbolic-ref HEAD)\" != \"refs/heads/$name\" ] ||\n \tdie \"cannot delete your current branch\"\n \n-nonempty=\n-branch_empty \"$name\" || nonempty=1\n-\n-[ -z \"$nonempty\" ] || [ -n \"$force\" ] || die \"branch is non-empty: $name\"\n+[ -z \"$force\" ] && { branch_empty \"$name\" || die \"branch is non-empty: $name\"; }\n \n \n ## Wipe out\n \n git update-ref -d \"refs/top-bases/$name\" \"$baserev\"\n-git update-ref -d \"refs/heads/$name\" \"$branchrev\"\n+[ -z \"$branchrev\" ] || git update-ref -d \"refs/heads/$name\" \"$branchrev\"\n \n # vim:noet\n-- \n1.6.0.4\n"},{"id":"299171","messageId":"1267365639-30387-1-git-send-email-thomas@schwinge.name","threadId":"22854","inReplyTo":"1267357174-21417-1-git-send-email-thomas@schwinge.name","subject":"[PATCH] tg-delete: Handle the case where the branch has been removed already, but the base is still left.","fromName":"Thomas Schwinge","fromEmail":"thomas@schwinge.name","sentAt":"2010-02-28T14:00:39Z","receivedAt":"2010-02-28T14:00:39Z","isPatch":true,"sender":{"key":"thomas@schwinge.name","avatar":"https://gravatar.com/avatar/52ddb7ca4856f40a2eb23eac2f499178ff17dcc372d055c6c41ab2ecc4d19ae8?d=mp&s=160"},"body":"A user might have used 'git branch -D B' to remove the branch B, and then\ncertain TopGit commands complain, because the base of branch B is still there.\n\nSigned-off-by: Thomas Schwinge <thomas@schwinge.name>\n\n---\n README       |    4 ++++\n tg-delete.sh |   15 ++++++++-------\n 2 files changed, 12 insertions(+), 7 deletions(-)\n\ndiff --git a/README b/README\nindex 495c70b..fc74ff8 100644\n--- a/README\n+++ b/README\n@@ -244,6 +244,10 @@ tg delete\n \tonly empty branch (base == head); use '-f' to remove\n \tnon-empty branch.\n \n+\tThe '-f' option is also useful to force removal of a branch's base, if\n+\tyou used 'git branch -D B' to remove the branch B, and then certain\n+\tTopGit commands complain, because the base of branch B is still there.\n+\n \tCurrently, this command will _NOT_ remove the branch from\n \tthe dependency list in other branches. You need to take\n \tcare of this _manually_. This is even more complicated\ndiff --git a/tg-delete.sh b/tg-delete.sh\nindex ab121c2..e1eea17 100644\n--- a/tg-delete.sh\n+++ b/tg-delete.sh\n@@ -3,7 +3,7 @@\n # (c) Petr Baudis <pasky@suse.cz>  2008\n # GPLv2\n \n-force= # Whether to delete non-empty branch\n+force= # Whether to delete non-empty branch, or branch where only the base is left.\n name=\n \n \n@@ -28,21 +28,22 @@ done\n \n [ -n \"$name\" ] || die \"no branch name specified\"\n branchrev=\"$(git rev-parse --verify \"$name\" 2>/dev/null)\" ||\n-\tdie \"invalid branch name: $name\"\n+\tif [ -n \"$force\" ]; then\n+\t\tinfo \"invalid branch name: $name; assuming it has been deleted already\"\n+\telse\n+\t\tdie \"invalid branch name: $name\"\n+\tfi\n baserev=\"$(git rev-parse --verify \"refs/top-bases/$name\" 2>/dev/null)\" ||\n \tdie \"not a TopGit topic branch: $name\"\n ! git symbolic-ref HEAD >/dev/null || [ \"$(git symbolic-ref HEAD)\" != \"refs/heads/$name\" ] ||\n \tdie \"cannot delete your current branch\"\n \n-nonempty=\n-branch_empty \"$name\" || nonempty=1\n-\n-[ -z \"$nonempty\" ] || [ -n \"$force\" ] || die \"branch is non-empty: $name\"\n+[ -z \"$force\" ] && { branch_empty \"$name\" || die \"branch is non-empty: $name\"; }\n \n \n ## Wipe out\n \n git update-ref -d \"refs/top-bases/$name\" \"$baserev\"\n-git update-ref -d \"refs/heads/$name\" \"$branchrev\"\n+[ -z \"$branchrev\" ] || git update-ref -d \"refs/heads/$name\" \"$branchrev\"\n \n # vim:noet\n-- \ntg: (341a371..) t/tg_delete_already_deleted (depends on: master)\n"}]}