{"thread":{"id":"40814","subject":"[PATCH v4 2/2] completion: add support for completing email aliases","startedAt":"2015-11-17T11:45:49Z","lastAt":"2015-11-17T11:45:50Z","messageCount":2,"participants":["Jacob Keller"],"isPatch":true,"patchVersion":4,"patchTotal":2},"messages":[{"id":"273427","messageId":"1447760750-21287-1-git-send-email-jacob.e.keller@intel.com","threadId":"40814","inReplyTo":null,"subject":"[PATCH v4 1/2] sendemail: teach git-send-email to dump alias names","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2015-11-17T11:45:49Z","receivedAt":"2015-11-17T11:45:49Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nAdd an option \"--dump-aliases\" which changes the default behavior of\ngit-send-email. This mode will simply read the alias files configured by\nsendemail.aliasesfile and sendemail.aliasfiletype and dump a list of all\nconfigured aliases, one per line. The intended use case for this option\nis the bash-completion script which will use it to autocomplete aliases\non the options which take addresses.\n\nAdd some tests for the new option using various alias file formats.\n\nA possible future extension to the alias dump format could be done by\nextending the --dump-aliases to take an optional argument defining the\nformat to display. This has not been done in this patch as no user of\nthis information has been identified.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n\nI also noticed a possible issue with the gnus format for mail addresses,\nin that the expansion of the alias does not allow spaces in its regular\nexpression, but I am not sure how best to resolve this or even if it's\nan issue. Anyone know?\n\nNotes:\n    - v2\n    * Add command --list-aliases to git-send-email\n    \n    - v3\n    * Add test\n    * change option to --dump-aliases\n    * dump both the alias and its expansion\n    \n    - v4\n    * Rework and extend tests\n    * Only print alias names for now, punt full format for when a use case is\n      identified\n    * Ensure no other options are used with --dump-aliases\n\n Documentation/git-send-email.txt | 11 ++++++\n git-send-email.perl              | 15 ++++++++\n t/t9001-send-email.sh            | 82 ++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 108 insertions(+)\n\ndiff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt\nindex b9134d234f53..771a7b5b0915 100644\n--- a/Documentation/git-send-email.txt\n+++ b/Documentation/git-send-email.txt\n@@ -10,6 +10,7 @@ SYNOPSIS\n --------\n [verse]\n 'git send-email' [options] <file|directory|rev-list options>...\n+'git send-email' --dump-aliases\n \n \n DESCRIPTION\n@@ -387,6 +388,16 @@ default to '--validate'.\n \tSend emails even if safety checks would prevent it.\n \n \n+Information\n+~~~~~~~~~~~\n+\n+--dump-aliases::\n+\tInstead of the normal operation, dump the shorthand alias names from\n+\tthe configured alias file(s), one per line in alphabetical order. Note,\n+\tthis only includes the alias name and not its expanded email addresses.\n+\tSee 'sendemail.aliasesfile' for more information about aliases.\n+\n+\n CONFIGURATION\n -------------\n \ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex e907e0eacf31..a475b0d75370 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -46,6 +46,7 @@ package main;\n sub usage {\n \tprint <<EOT;\n git send-email [options] <file | directory | rev-list options >\n+git send-email --dump-aliases\n \n   Composing:\n     --from                  <str>  * Email From:\n@@ -101,6 +102,9 @@ git send-email [options] <file | directory | rev-list options >\n                                      `git format-patch` ones.\n     --force                        * Send even if safety checks would prevent it.\n \n+  Information:\n+    --dump-aliases                 * Dump configured aliases and exit.\n+\n EOT\n \texit(1);\n }\n@@ -180,6 +184,7 @@ my ($quiet, $dry_run) = (0, 0);\n my $format_patch;\n my $compose_filename;\n my $force = 0;\n+my $dump_aliases = 0;\n \n # Handle interactive edition of files.\n my $multiedit;\n@@ -291,6 +296,11 @@ $SIG{INT}  = \\&signal_handler;\n \n my $help;\n my $rc = GetOptions(\"h\" => \\$help,\n+                    \"dump-aliases\" => \\$dump_aliases);\n+usage() unless $rc;\n+die \"--dump-aliases incompatible with other options\\n\"\n+    if !$help and $dump_aliases and @ARGV;\n+$rc = GetOptions(\n \t\t    \"sender|from=s\" => \\$sender,\n                     \"in-reply-to=s\" => \\$initial_reply_to,\n \t\t    \"subject=s\" => \\$initial_subject,\n@@ -551,6 +561,11 @@ if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) {\n \t}\n }\n \n+if ($dump_aliases) {\n+    print \"$_\\n\" for (sort keys %aliases);\n+    exit(0);\n+}\n+\n # is_format_patch_arg($f) returns 0 if $f names a patch, or 1 if\n # $f is a revision list specification to be passed to format-patch.\n sub is_format_patch_arg {\ndiff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh\nindex 5b4a5ce06b94..3c49536e0e8d 100755\n--- a/t/t9001-send-email.sh\n+++ b/t/t9001-send-email.sh\n@@ -1555,6 +1555,88 @@ test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '\n \tgrep \"^!someone@example\\.org!$\" commandline1\n '\n \n+test_dump_aliases () {\n+\tmsg=\"$1\" && shift &&\n+\tfiletype=\"$1\" && shift &&\n+\tprintf '%s\\n' \"$@\" >expect &&\n+\tcat >.tmp-email-aliases &&\n+\n+\ttest_expect_success $PREREQ \"$msg\" '\n+\t\tclean_fake_sendmail && rm -fr outdir &&\n+\t\tgit config --replace-all sendemail.aliasesfile \\\n+\t\t\t\"$(pwd)/.tmp-email-aliases\" &&\n+\t\tgit config sendemail.aliasfiletype \"$filetype\" &&\n+\t\tgit send-email --dump-aliases 2>errors >actual &&\n+\t\ttest_cmp expect actual\n+\t'\n+}\n+\n+test_dump_aliases '--dump-aliases sendmail format' \\\n+\t'sendmail' \\\n+\t'abgroup' \\\n+\t'alice' \\\n+\t'bcgrp' \\\n+\t'bob' \\\n+\t'chloe' <<-\\EOF\n+\talice: Alice W Land <awol@example.com>\n+\tbob: Robert Bobbyton <bob@example.com>\n+\tchloe: chloe@example.com\n+\tabgroup: alice, bob\n+\tbcgrp: bob, chloe, Other <o@example.com>\n+\tEOF\n+\n+test_dump_aliases '--dump-aliases mutt format' \\\n+\t'mutt' \\\n+\t'alice' \\\n+\t'bob' \\\n+\t'chloe' \\\n+\t'donald' <<-\\EOF\n+\talias alice Alice W Land <awol@example.com>\n+\talias donald Donald C Carlton <donc@example.com>\n+\talias bob Robert Bobbyton <bob@example.com>\n+\talias chloe chloe@example.com\n+\tEOF\n+\n+test_dump_aliases '--dump-aliases mailrc format' \\\n+\t'mailrc' \\\n+\t'alice' \\\n+\t'bob' \\\n+\t'chloe' \\\n+\t'eve' <<-\\EOF\n+\talias alice   Alice W Land <awol@example.com>\n+\talias eve     Eve <eve@example.com>\n+\talias bob     Robert Bobbyton <bob@example.com>\n+\talias chloe   chloe@example.com\n+\tEOF\n+\n+test_dump_aliases '--dump-aliases pine format' \\\n+\t'pine' \\\n+\t'alice' \\\n+\t'bob' \\\n+\t'chloe' \\\n+\t'eve' <<-\\EOF\n+\talice\tAlice W Land\t<awol@example.com>\n+\teve\tEve\t<eve@example.com>\n+\tbob\tRobert\tBobbyton <bob@example.com>\n+\tchloe\t\tchloe@example.com\n+\tEOF\n+\n+test_dump_aliases '--dump-aliases gnus format' \\\n+\t'gnus' \\\n+\t'alice' \\\n+\t'bob' \\\n+\t'chloe' \\\n+\t'eve' <<-\\EOF\n+\t(define-mail-alias \"alice\" \"awol@example.com\")\n+\t(define-mail-alias \"eve\" \"eve@example.com\")\n+\t(define-mail-alias \"bob\" \"bob@example.com\")\n+\t(define-mail-alias \"chloe\" \"chloe@example.com\")\n+\tEOF\n+\n+test_expect_success '--dump-aliases must be used alone' '\n+\ttest_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting\n+'\n+\n test_sendmail_aliases () {\n \tmsg=\"$1\" && shift &&\n \texpect=\"$@\" &&\n-- \n2.6.3.491.g3e3f6ce\n"},{"id":"273426","messageId":"1447760750-21287-2-git-send-email-jacob.e.keller@intel.com","threadId":"40814","inReplyTo":"1447760750-21287-1-git-send-email-jacob.e.keller@intel.com","subject":"[PATCH v4 2/2] completion: add support for completing email aliases","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2015-11-17T11:45:50Z","receivedAt":"2015-11-17T11:45:50Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nUsing the new --dump-aliases option from git-send-email, add completion\nfor --to, --cc, --bcc, and --from with the available configured aliases.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n\nNotes:\n    - v2\n    * Use git-send-email for parsing instead of re-implementing it in awk\n    \n    - v3\n    * update for change to git-send-email\n    * add support for \"--from\"\n    \n    - v2\n    * reuse parsing from git-send-email via --list-aliases\n\n contrib/completion/git-completion.bash | 16 ++++++++++++++++\n 1 file changed, 16 insertions(+)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 482ca84b451b..111b05302bc7 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -10,6 +10,7 @@\n #    *) local and remote tag names\n #    *) .git/remotes file names\n #    *) git 'subcommands'\n+#    *) git email aliases for git-send-email\n #    *) tree paths within 'ref:path/to/file' expressions\n #    *) file paths within current working directory and index\n #    *) common --long-options\n@@ -1711,6 +1712,15 @@ __git_send_email_suppresscc_options=\"author self cc bodycc sob cccmd body all\"\n \n _git_send_email ()\n {\n+\tcase \"$prev\" in\n+\t--to|--cc|--bcc|--from)\n+\t\t__gitcomp \"\n+\t\t$(git --git-dir=\"$(__gitdir)\" send-email --dump-aliases 2>/dev/null)\n+\t\t\" \"\" \"\"\n+\t\treturn\n+\t\t;;\n+\tesac\n+\n \tcase \"$cur\" in\n \t--confirm=*)\n \t\t__gitcomp \"\n@@ -1735,6 +1745,12 @@ _git_send_email ()\n \t\t\t\" \"\" \"${cur##--thread=}\"\n \t\treturn\n \t\t;;\n+\t--to=*|--cc=*|--bcc=*|--from=*)\n+\t\t__gitcomp \"\n+\t\t$(git --git-dir=\"$(__gitdir)\" send-email --dump-aliases 2>/dev/null)\n+\t\t\" \"\" \"${cur#--*=}\"\n+\t\treturn\n+\t\t;;\n \t--*)\n \t\t__gitcomp \"--annotate --bcc --cc --cc-cmd --chain-reply-to\n \t\t\t--compose --confirm= --dry-run --envelope-sender\n-- \n2.6.3.491.g3e3f6ce\n"}]}