{"thread":{"id":"38387","subject":"[PATCH] branch: add support for --dry-run option","startedAt":"2015-01-17T07:35:59Z","lastAt":"2015-01-22T10:17:08Z","messageCount":5,"participants":["Alexander Kuleshov","Philip Oakley","Michael J Gruber","Scott Schmit"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"254846","messageId":"1421480159-4848-1-git-send-email-kuleshovmail@gmail.com","threadId":"38387","inReplyTo":null,"subject":"[PATCH] branch: add support for --dry-run option","fromName":"Alexander Kuleshov","fromEmail":"kuleshovmail@gmail.com","sentAt":"2015-01-17T07:35:59Z","receivedAt":"2015-01-17T07:35:59Z","isPatch":true,"sender":{"key":"kuleshovmail@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2699235?v=4"},"body":"This patch adds support -d/--dry-run option for branch(es) deletion.\nIf -d/--dry-run option passed to git branch -d branch..., branch(es)\nwill not be removed, instead just print list of branches that are\nto be removed.\n\nFor example:\n\n    $ git branch\n    a\n    b\n    c\n    * master\n\n    $ git branch -d -n a b c\n    delete branch 'a' (261c0d1)\n    delete branch 'b' (261c0d1)\n    delete branch 'c' (261c0d1)\n\nSigned-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n---\n Documentation/git-branch.txt | 11 +++++++++--\n builtin/branch.c             | 13 +++++++++++++\n 2 files changed, 22 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\nindex 311b336..32ea581 100644\n--- a/Documentation/git-branch.txt\n+++ b/Documentation/git-branch.txt\n@@ -16,7 +16,7 @@ SYNOPSIS\n 'git branch' (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]\n 'git branch' --unset-upstream [<branchname>]\n 'git branch' (-m | -M) [<oldbranch>] <newbranch>\n-'git branch' (-d | -D) [-r] <branchname>...\n+'git branch' (-d | -D) [--dry-run | -n] [-r] <branchname>...\n 'git branch' --edit-description [<branchname>]\n \n DESCRIPTION\n@@ -63,7 +63,9 @@ to happen.\n \n With a `-d` or `-D` option, `<branchname>` will be deleted.  You may\n specify more than one branch for deletion.  If the branch currently\n-has a reflog then the reflog will also be deleted.\n+has a reflog then the reflog will also be deleted. If passed `-n` or\n+`--dry-run` option, branch(es) will be not removed, but show a list of\n+branches that are to be removed.\n \n Use `-r` together with `-d` to delete remote-tracking branches. Note, that it\n only makes sense to delete remote-tracking branches if they no longer exist\n@@ -83,6 +85,11 @@ OPTIONS\n -D::\n \tDelete a branch irrespective of its merged status.\n \n+-n::\n+--dry-run::\n+\tDon't remove the branch(es), but show a list of branches that are\n+\tto be removed.\n+\n -l::\n --create-reflog::\n \tCreate the branch's reflog.  This activates recording of\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex d8949cb..4a35a2f 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -61,6 +61,7 @@ static unsigned char merge_filter_ref[20];\n \n static struct string_list output = STRING_LIST_INIT_DUP;\n static unsigned int colopts;\n+static int branch_delete_show_only;\n \n static int parse_branch_color_slot(const char *slot)\n {\n@@ -255,6 +256,17 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n \t\t\tcontinue;\n \t\t}\n \n+\t\tif (branch_delete_show_only) {\n+\t\t\tprintf(remote_branch\n+\t\t\t       ? _(\"delete remote branch '%s' (%s)\\n\")\n+\t\t\t       : _(\"delete branch '%s' (%s)\\n\"),\n+\t\t\t       bname.buf,\n+\t\t\t       (flags & REF_ISBROKEN) ? \"broken\"\n+\t\t\t       : (flags & REF_ISSYMREF) ? target\n+\t\t\t       : find_unique_abbrev(sha1, DEFAULT_ABBREV));\n+\t\t\tcontinue;\n+\t\t}\n+\n \t\tif (delete_ref(name, sha1, REF_NODEREF)) {\n \t\t\terror(remote_branch\n \t\t\t      ? _(\"Error deleting remote branch '%s'\")\n@@ -840,6 +852,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\t\tREF_REMOTE_BRANCH | REF_LOCAL_BRANCH),\n \t\tOPT_BIT('d', \"delete\", &delete, N_(\"delete fully merged branch\"), 1),\n \t\tOPT_BIT('D', NULL, &delete, N_(\"delete branch (even if not merged)\"), 2),\n+\t\tOPT__DRY_RUN(&branch_delete_show_only, N_(\"dry run\")),\n \t\tOPT_BIT('m', \"move\", &rename, N_(\"move/rename a branch and its reflog\"), 1),\n \t\tOPT_BIT('M', NULL, &rename, N_(\"move/rename a branch, even if target exists\"), 2),\n \t\tOPT_BOOL(0, \"list\", &list, N_(\"list branch names\")),\n-- \n2.3.0.rc0.286.ga3dc223.dirty\n"},{"id":"254851","messageId":"012FBD7D0B7848AC83D6D8C07C6C78EC@PhilipOakley","threadId":"38387","inReplyTo":"1421480159-4848-1-git-send-email-kuleshovmail@gmail.com","subject":"Re: [PATCH] branch: add support for --dry-run option","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.org","sentAt":null,"receivedAt":"2015-01-17T11:18:51Z","isPatch":true,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"From: \"Alexander Kuleshov\" <kuleshovmail@gmail.com>\n> This patch adds support -d/--dry-run option for branch(es) deletion.\n> If -d/--dry-run option passed to git branch -d branch..., branch(es)\n\nsurely s|-d/--dry-run|-n/--dry-run|\n-n is the short version of --dryrun. -d is already in use.\n\n> will not be removed, instead just print list of branches that are\n> to be removed.\n> \n[...]\n--\nPhilip\n"},{"id":"254880","messageId":"54BD12C3.5050802@drmicha.warpmail.net","threadId":"38387","inReplyTo":"1421480159-4848-1-git-send-email-kuleshovmail@gmail.com","subject":"Re: [PATCH] branch: add support for --dry-run option","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2015-01-19T14:20:51Z","receivedAt":"2015-01-19T14:20:51Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Alexander Kuleshov schrieb am 17.01.2015 um 08:35:\n> This patch adds support -d/--dry-run option for branch(es) deletion.\n> If -d/--dry-run option passed to git branch -d branch..., branch(es)\n> will not be removed, instead just print list of branches that are\n> to be removed.\n> \n> For example:\n> \n>     $ git branch\n>     a\n>     b\n>     c\n>     * master\n> \n>     $ git branch -d -n a b c\n>     delete branch 'a' (261c0d1)\n>     delete branch 'b' (261c0d1)\n>     delete branch 'c' (261c0d1)\n\nIs there a case where deleting \"a b c\" would not delete \"a b c\"?\n\nIn other words: What new information does a dry-run give the user, other\nthan what \"branch --list -v\" would give already? (We could need a\nshortcut on the latter, but that is a different topic.)\n\nMichael\n"},{"id":"255053","messageId":"20150122013723.GA3795@odin.ulthar.us","threadId":"38387","inReplyTo":"54BD12C3.5050802@drmicha.warpmail.net","subject":"Re: [PATCH] branch: add support for --dry-run option","fromName":"Scott Schmit","fromEmail":"i.grok@comcast.net","sentAt":"2015-01-22T01:37:23Z","receivedAt":"2015-01-22T01:37:23Z","isPatch":true,"sender":{"key":"i.grok@comcast.net","avatar":null},"body":"On Mon, Jan 19, 2015 at 03:20:51PM +0100, Michael J Gruber wrote:\n> Alexander Kuleshov schrieb am 17.01.2015 um 08:35:\n> > This patch adds support -d/--dry-run option for branch(es) deletion.\n> > If -d/--dry-run option passed to git branch -d branch..., branch(es)\n> > will not be removed, instead just print list of branches that are\n> > to be removed.\n> > \n> > For example:\n> > \n> >     $ git branch\n> >     a\n> >     b\n> >     c\n> >     * master\n> > \n> >     $ git branch -d -n a b c\n> >     delete branch 'a' (261c0d1)\n> >     delete branch 'b' (261c0d1)\n> >     delete branch 'c' (261c0d1)\n> \n> Is there a case where deleting \"a b c\" would not delete \"a b c\"?\n\nSure:\n$ cd /tmp/\n$ git init foo\nInitialized empty Git repository in /tmp/foo/.git/\n$ cd foo/\n$ touch .gitignore\n$ git add .gitignore \n$ git commit -m init\n[master (root-commit) fde5138] init\n 1 file changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 .gitignore\n$ git checkout -b a\nSwitched to a new branch 'a'\n$ git branch -d a\nerror: Cannot delete the branch 'a' which you are currently on.\n$ touch file\n$ git add file\n$ git commit -m 'add file'\n[a e2c2ece] add file\n 1 file changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 file\n$ git checkout -b b master\nSwitched to a new branch 'b'\n$ git branch -d a\nerror: The branch 'a' is not fully merged.\nIf you are sure you want to delete it, run 'git branch -D a'.\n\n-- \nScott Schmit\n"},{"id":"255076","messageId":"54C0CE24.9040908@drmicha.warpmail.net","threadId":"38387","inReplyTo":"20150122013723.GA3795@odin.ulthar.us","subject":"Re: [PATCH] branch: add support for --dry-run option","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2015-01-22T10:17:08Z","receivedAt":"2015-01-22T10:17:08Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Scott Schmit schrieb am 22.01.2015 um 02:37:\n> On Mon, Jan 19, 2015 at 03:20:51PM +0100, Michael J Gruber wrote:\n>> Alexander Kuleshov schrieb am 17.01.2015 um 08:35:\n>>> This patch adds support -d/--dry-run option for branch(es) deletion.\n>>> If -d/--dry-run option passed to git branch -d branch..., branch(es)\n>>> will not be removed, instead just print list of branches that are\n>>> to be removed.\n>>>\n>>> For example:\n>>>\n>>>     $ git branch\n>>>     a\n>>>     b\n>>>     c\n>>>     * master\n>>>\n>>>     $ git branch -d -n a b c\n>>>     delete branch 'a' (261c0d1)\n>>>     delete branch 'b' (261c0d1)\n>>>     delete branch 'c' (261c0d1)\n>>\n>> Is there a case where deleting \"a b c\" would not delete \"a b c\"?\n> \n> Sure:\n> $ cd /tmp/\n> $ git init foo\n> Initialized empty Git repository in /tmp/foo/.git/\n> $ cd foo/\n> $ touch .gitignore\n> $ git add .gitignore \n> $ git commit -m init\n> [master (root-commit) fde5138] init\n>  1 file changed, 0 insertions(+), 0 deletions(-)\n>  create mode 100644 .gitignore\n> $ git checkout -b a\n> Switched to a new branch 'a'\n> $ git branch -d a\n> error: Cannot delete the branch 'a' which you are currently on.\n> $ touch file\n> $ git add file\n> $ git commit -m 'add file'\n> [a e2c2ece] add file\n>  1 file changed, 0 insertions(+), 0 deletions(-)\n>  create mode 100644 file\n> $ git checkout -b b master\n> Switched to a new branch 'b'\n> $ git branch -d a\n> error: The branch 'a' is not fully merged.\n> If you are sure you want to delete it, run 'git branch -D a'.\n\nYes, and that is something that should go into the commit message. \"Why\ndo you want to add --dry-run? Because -d deletes only fully merged\nbranches.\"\n\nIt should have been there in the 1st place, rather than forcing us to\nask the question that always needs to answered for a patch: What is the\nintention? What is it good for?\n\nIn this case, we have other means to accomplish the same (--list -v),\nand they are more natural if you want get information about the state of\nthe branches (\"list verbose\") than doing \"delete dry-run\".\n\nMichael\n"}]}