{"thread":{"id":"38392","subject":"[PATCH v2] branch: add support for --dry-run option","startedAt":"2015-01-17T16:39:34Z","lastAt":"2015-01-17T16:39:34Z","messageCount":1,"participants":["Alexander Kuleshov"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"254854","messageId":"1421512774-3728-1-git-send-email-kuleshovmail@gmail.com","threadId":"38392","inReplyTo":null,"subject":"[PATCH v2] branch: add support for --dry-run option","fromName":"Alexander Kuleshov","fromEmail":"kuleshovmail@gmail.com","sentAt":"2015-01-17T16:39:34Z","receivedAt":"2015-01-17T16:39:34Z","isPatch":true,"sender":{"key":"kuleshovmail@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2699235?v=4"},"body":"This patch adds support -n/--dry-run option for branch(es) deletion.\nIf -n/--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"}]}