{"thread":{"id":"1791","subject":"deleting a branch","startedAt":"2005-09-13T15:39:26Z","lastAt":"2005-09-14T16:15:19Z","messageCount":6,"participants":["Chuck Lever","Junio C Hamano","Daniel Barkalow"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"8462","messageId":"4326F2AE.50108@citi.umich.edu","threadId":"1791","inReplyTo":null,"subject":"deleting a branch","fromName":"Chuck Lever","fromEmail":"cel@citi.umich.edu","sentAt":"2005-09-13T15:39:26Z","receivedAt":"2005-09-13T15:39:26Z","isPatch":false,"sender":{"key":"cel@citi.umich.edu","avatar":null},"body":"a couple of newbie questions.\n\n1.  how do i delete a branch?\n\n2.  is there a conventional place where branch description files reside?\n\n\nbegin:vcard\nfn:Chuck Lever\nn:Lever;Charles\norg:Network Appliance, Incorporated;Linux NFS Client Development\nadr:535 West William Street, Suite 3100;;Center for Information Technology Integration;Ann Arbor;MI;48103-4943;USA\nemail;internet:cel@citi.umich.edu\ntitle:Member of Technical Staff\ntel;work:+1 734 763 4415\ntel;fax:+1 734 763 4434\ntel;home:+1 734 668 1089\nx-mozilla-html:FALSE\nurl:http://www.monkey.org/~cel/\nversion:2.1\nend:vcard\n\n"},{"id":"8464","messageId":"7v4q8p3qd8.fsf@assigned-by-dhcp.cox.net","threadId":"1791","inReplyTo":"4326F2AE.50108@citi.umich.edu","subject":"Re: deleting a branch","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-09-13T16:05:23Z","receivedAt":"2005-09-13T16:05:23Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Chuck Lever <cel@citi.umich.edu> writes:\n\n> a couple of newbie questions.\n>\n> 1.  how do i delete a branch?\n\n\"rm -f .git/refs/heads/no-longer-needed\".  Make sure your\nworking tree is not on that branch (i.e. .git/HEAD should not be\npointing at it).\n\nI have not introduced \"git branch -d no-longer-needed\" because\nI think that should do a bit more than \"rm -f\".  For example:\n\n - making sure you are not on that branch (obvious),\n\n - check if all changes on that branch are included in the\n   master branch or some other branch (easy if we hardcode \"master\";\n   checking all other branches might be nicer but expensive).\n\n - otherwise tell the user this and that changes will be forever\n   lost and get a confirmation before removing.\n\n> 2.  is there a conventional place where branch description files reside?\n\nNo, but somebody proposed a convention a couple of days ago.\n"},{"id":"8465","messageId":"Pine.LNX.4.63.0509131217490.23242@iabervon.org","threadId":"1791","inReplyTo":"7v4q8p3qd8.fsf@assigned-by-dhcp.cox.net","subject":"Re: deleting a branch","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2005-09-13T16:23:37Z","receivedAt":"2005-09-13T16:23:37Z","isPatch":false,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Tue, 13 Sep 2005, Junio C Hamano wrote:\n\n> \"rm -f .git/refs/heads/no-longer-needed\".  Make sure your\n> working tree is not on that branch (i.e. .git/HEAD should not be\n> pointing at it).\n> \n> I have not introduced \"git branch -d no-longer-needed\" because\n> I think that should do a bit more than \"rm -f\".  For example:\n> \n>  - making sure you are not on that branch (obvious),\n> \n>  - check if all changes on that branch are included in the\n>    master branch or some other branch (easy if we hardcode \"master\";\n>    checking all other branches might be nicer but expensive).\n\nYou could check HEAD. I think the most common cases would either be that \nyou just created a branch from HEAD and changed your mind, or that you've \njust merged the branch into something. Other that that, I think the common \ncase is that you've made patches, sent them off, and they were accepted. \nIn the first two, you're probably on the branch that includes or matches \nthe one you're deleting; on the third, we want user confirmation, since \nit's external to the system.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"8509","messageId":"7vvf14ox39.fsf@assigned-by-dhcp.cox.net","threadId":"1791","inReplyTo":"4326F2AE.50108@citi.umich.edu","subject":"[PATCH] git-branch -d <branch>: delete unused branch.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-09-14T08:46:50Z","receivedAt":"2005-09-14T08:46:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The new flag '-d' lets you delete a branch.  For safety, it does not\nlets you delete the branch you are currently on, nor a branch that\nhas been fully merged into your current branch.\n\nThe credit for the safety check idea goes to Daniel Barkalow.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n\n git-branch.sh |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++------\n 1 files changed, 54 insertions(+), 6 deletions(-)\n\n6a714989f83ccb93188dc37791da8a0f2e32cabe\ndiff --git a/git-branch.sh b/git-branch.sh\n--- a/git-branch.sh\n+++ b/git-branch.sh\n@@ -3,7 +3,7 @@\n . git-sh-setup || die \"Not a git archive\"\n \n usage () {\n-    echo >&2 \"usage: $(basename $0)\"' [<branchname> [start-point]]\n+    echo >&2 \"usage: $(basename $0)\"' [-d <branch>] | [<branch> [start-point]]\n \n If no arguments, show available branches and mark current branch with a star.\n If one argument, create a new branch <branchname> based off of current HEAD.\n@@ -12,6 +12,59 @@ If two arguments, create a new branch <b\n     exit 1\n }\n \n+delete_branch () {\n+    option=\"$1\" branch_name=\"$2\"\n+    headref=$(readlink \"$GIT_DIR/HEAD\" | sed -e 's|^refs/heads/||')\n+    case \",$headref,\" in\n+    \",$branch_name,\")\n+\tdie \"Cannot delete the branch you are on.\" ;;\n+    ,,)\n+\tdie \"What branch are you on anyway?\" ;;\n+    esac\n+    branch=$(cat \"$GIT_DIR/refs/heads/$branch_name\") &&\n+\tbranch=$(git-rev-parse --verify \"$branch^0\") ||\n+\t    die \"Seriously, what branch are you talking about?\"\n+    case \"$option\" in\n+    -D)\n+\t;;\n+    *)\n+\tmbs=$(git-merge-base -a \"$branch\" HEAD | tr '\\012' ' ')\n+\tcase \" $mbs \" in\n+\t*' '$branch' '*)\n+\t    # the merge base of branch and HEAD contains branch --\n+\t    # which means that the HEAD contains everything in the HEAD.\n+\t    ;;\n+\t*)\n+\t    echo >&2 \"The branch '$branch_name' is not a strict subset of your current HEAD.\n+If you are sure you want to delete it, run 'git branch -D $branch_name'.\"\n+\t    exit 1\n+\t    ;;\n+\tesac\n+\t;;\n+    esac\n+    rm -f \"$GIT_DIR/refs/heads/$branch_name\"\n+    echo \"Deleted branch $branch_name.\"\n+    exit 0\n+}\n+\n+while case \"$#,$1\" in 0,*) break ;; *,-*) ;; *) break ;; esac\n+do\n+\tcase \"$1\" in\n+\t-d | -D)\n+\t\tdelete_branch \"$1\" \"$2\"\n+\t\texit\n+\t\t;;\n+\t--)\n+\t\tshift\n+\t\tbreak\n+\t\t;;\n+\t-*)\n+\t\tusage\n+\t\t;;\n+\tesac\n+\tshift\n+done\n+\n case \"$#\" in\n 0)\n \theadref=$(readlink \"$GIT_DIR/HEAD\" | sed -e 's|^refs/heads/||')\n@@ -36,11 +89,6 @@ case \"$#\" in\n esac\n branchname=\"$1\"\n \n-case \"$branchname\" in\n--*)\n-\tusage;;\n-esac\n-\n rev=$(git-rev-parse --verify \"$head\") || exit\n \n [ -e \"$GIT_DIR/refs/heads/$branchname\" ] && die \"$branchname already exists\"\n"},{"id":"8522","messageId":"432839B6.2070103@citi.umich.edu","threadId":"1791","inReplyTo":"7vvf14ox39.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-branch -d <branch>: delete unused branch.","fromName":"Chuck Lever","fromEmail":"cel@citi.umich.edu","sentAt":"2005-09-14T14:54:46Z","receivedAt":"2005-09-14T14:54:46Z","isPatch":true,"sender":{"key":"cel@citi.umich.edu","avatar":null},"body":"what if you want to throw away work in a branch even if it's not merged? \n  doesn't the safety check prevent that?\n\nJunio C Hamano wrote:\n> The new flag '-d' lets you delete a branch.  For safety, it does not\n> lets you delete the branch you are currently on, nor a branch that\n> has been fully merged into your current branch.\n> \n> The credit for the safety check idea goes to Daniel Barkalow.\n> \n> Signed-off-by: Junio C Hamano <junkio@cox.net>\n> \n> ---\n> \n>  git-branch.sh |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++------\n>  1 files changed, 54 insertions(+), 6 deletions(-)\n> \n> 6a714989f83ccb93188dc37791da8a0f2e32cabe\n> diff --git a/git-branch.sh b/git-branch.sh\n> --- a/git-branch.sh\n> +++ b/git-branch.sh\n> @@ -3,7 +3,7 @@\n>  . git-sh-setup || die \"Not a git archive\"\n>  \n>  usage () {\n> -    echo >&2 \"usage: $(basename $0)\"' [<branchname> [start-point]]\n> +    echo >&2 \"usage: $(basename $0)\"' [-d <branch>] | [<branch> [start-point]]\n>  \n>  If no arguments, show available branches and mark current branch with a star.\n>  If one argument, create a new branch <branchname> based off of current HEAD.\n> @@ -12,6 +12,59 @@ If two arguments, create a new branch <b\n>      exit 1\n>  }\n>  \n> +delete_branch () {\n> +    option=\"$1\" branch_name=\"$2\"\n> +    headref=$(readlink \"$GIT_DIR/HEAD\" | sed -e 's|^refs/heads/||')\n> +    case \",$headref,\" in\n> +    \",$branch_name,\")\n> +\tdie \"Cannot delete the branch you are on.\" ;;\n> +    ,,)\n> +\tdie \"What branch are you on anyway?\" ;;\n> +    esac\n> +    branch=$(cat \"$GIT_DIR/refs/heads/$branch_name\") &&\n> +\tbranch=$(git-rev-parse --verify \"$branch^0\") ||\n> +\t    die \"Seriously, what branch are you talking about?\"\n> +    case \"$option\" in\n> +    -D)\n> +\t;;\n> +    *)\n> +\tmbs=$(git-merge-base -a \"$branch\" HEAD | tr '\\012' ' ')\n> +\tcase \" $mbs \" in\n> +\t*' '$branch' '*)\n> +\t    # the merge base of branch and HEAD contains branch --\n> +\t    # which means that the HEAD contains everything in the HEAD.\n> +\t    ;;\n> +\t*)\n> +\t    echo >&2 \"The branch '$branch_name' is not a strict subset of your current HEAD.\n> +If you are sure you want to delete it, run 'git branch -D $branch_name'.\"\n> +\t    exit 1\n> +\t    ;;\n> +\tesac\n> +\t;;\n> +    esac\n> +    rm -f \"$GIT_DIR/refs/heads/$branch_name\"\n> +    echo \"Deleted branch $branch_name.\"\n> +    exit 0\n> +}\n> +\n> +while case \"$#,$1\" in 0,*) break ;; *,-*) ;; *) break ;; esac\n> +do\n> +\tcase \"$1\" in\n> +\t-d | -D)\n> +\t\tdelete_branch \"$1\" \"$2\"\n> +\t\texit\n> +\t\t;;\n> +\t--)\n> +\t\tshift\n> +\t\tbreak\n> +\t\t;;\n> +\t-*)\n> +\t\tusage\n> +\t\t;;\n> +\tesac\n> +\tshift\n> +done\n> +\n>  case \"$#\" in\n>  0)\n>  \theadref=$(readlink \"$GIT_DIR/HEAD\" | sed -e 's|^refs/heads/||')\n> @@ -36,11 +89,6 @@ case \"$#\" in\n>  esac\n>  branchname=\"$1\"\n>  \n> -case \"$branchname\" in\n> --*)\n> -\tusage;;\n> -esac\n> -\n>  rev=$(git-rev-parse --verify \"$head\") || exit\n>  \n>  [ -e \"$GIT_DIR/refs/heads/$branchname\" ] && die \"$branchname already exists\"\n> \n\n\n\nbegin:vcard\nfn:Chuck Lever\nn:Lever;Charles\norg:Network Appliance, Incorporated;Linux NFS Client Development\nadr:535 West William Street, Suite 3100;;Center for Information Technology Integration;Ann Arbor;MI;48103-4943;USA\nemail;internet:cel@citi.umich.edu\ntitle:Member of Technical Staff\ntel;work:+1 734 763 4415\ntel;fax:+1 734 763 4434\ntel;home:+1 734 668 1089\nx-mozilla-html:FALSE\nurl:http://www.monkey.org/~cel/\nversion:2.1\nend:vcard\n\n"},{"id":"8530","messageId":"7vd5nbpqw8.fsf@assigned-by-dhcp.cox.net","threadId":"1791","inReplyTo":"432839B6.2070103@citi.umich.edu","subject":"Re: [PATCH] git-branch -d <branch>: delete unused branch.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-09-14T16:15:19Z","receivedAt":"2005-09-14T16:15:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Chuck Lever <cel@citi.umich.edu> writes:\n\n> what if you want to throw away work in a branch even if it's not merged? \n>  doesn't the safety check prevent that?\n\nYes.  And you would get instructions on what to do from the\ncommand upon refusal.\n"}]}