{"thread":{"id":"6764","subject":"[PATCH 2/2] Allow aliases to expand to shell commands","startedAt":"2007-02-11T00:33:56Z","lastAt":"2007-02-11T16:32:23Z","messageCount":4,"participants":["Theodore Ts'o","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"34149","messageId":"11711540383470-git-send-email-tytso@mit.edu","threadId":"6764","inReplyTo":null,"subject":"[PATCH 0/2] Respun patches for git aliases enhancement","fromName":"Theodore Ts'o","fromEmail":"tytso@mit.edu","sentAt":"2007-02-11T00:33:56Z","receivedAt":"2007-02-11T00:33:56Z","isPatch":true,"sender":{"key":"tytso@mit.edu","avatar":"https://avatars.githubusercontent.com/u/51416?v=4"},"body":"These patches have been respun to fix a spelling typo and in response\nto comments from Johannes.\n\n\t\t\t\t\t\t- Ted\n"},{"id":"34150","messageId":"1171154038778-git-send-email-tytso@mit.edu","threadId":"6764","inReplyTo":"11711540383470-git-send-email-tytso@mit.edu","subject":"[PATCH 1/2] Print a sane error message if an alias expands to an invalid git command","fromName":"Theodore Ts'o","fromEmail":"tytso@mit.edu","sentAt":"2007-02-11T00:33:57Z","receivedAt":"2007-02-11T00:33:57Z","isPatch":true,"sender":{"key":"tytso@mit.edu","avatar":"https://avatars.githubusercontent.com/u/51416?v=4"},"body":"Signed-off-by: \"Theodore Ts'o\" <tytso@mit.edu>\n---\n git.c |    9 ++++++++-\n 1 files changed, 8 insertions(+), 1 deletions(-)\n\ndiff --git a/git.c b/git.c\nindex 82a8357..c43d4ff 100644\n--- a/git.c\n+++ b/git.c\n@@ -387,8 +387,15 @@ int main(int argc, const char **argv, char **envp)\n \t\tdone_alias = 1;\n \t}\n \n-\tif (errno == ENOENT)\n+\tif (errno == ENOENT) {\n+\t\tif (done_alias) {\n+\t\t\tfprintf(stderr, \"Expansion of alias '%s' failed; \"\n+\t\t\t\t\"'%s' is not a git-command\\n\",\n+\t\t\t\tcmd, argv[0]);\n+\t\t\texit(1);\n+\t\t}\n \t\thelp_unknown_cmd(cmd);\n+\t}\n \n \tfprintf(stderr, \"Failed to run command '%s': %s\\n\",\n \t\tcmd, strerror(errno));\n-- \n1.5.0.rc4.2.g4249\n"},{"id":"34148","messageId":"1171154038770-git-send-email-tytso@mit.edu","threadId":"6764","inReplyTo":"1171154038778-git-send-email-tytso@mit.edu","subject":"[PATCH 2/2] Allow aliases to expand to shell commands","fromName":"Theodore Ts'o","fromEmail":"tytso@mit.edu","sentAt":"2007-02-11T00:33:58Z","receivedAt":"2007-02-11T00:33:58Z","isPatch":true,"sender":{"key":"tytso@mit.edu","avatar":"https://avatars.githubusercontent.com/u/51416?v=4"},"body":"If the alias expansion is prefixed with an exclamation point, treat\nit as a shell command which is run using system(3).\n\nSigned-off-by: \"Theodore Ts'o\" <tytso@mit.edu>\n---\n Documentation/config.txt |    6 ++++++\n git.c                    |   10 ++++++++++\n 2 files changed, 16 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 4e650af..e6e9409 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -222,6 +222,12 @@ alias.*::\n \tspaces, the usual shell quoting and escaping is supported.\n \tquote pair and a backslash can be used to quote them.\n \n+\tIf the alias expansion is prefixed with an exclamation point,\n+\tit will be treated as a shell command.  For example, defining\n+\t\"alias.new = !gitk --all --not ORIG_HEAD\", the invocation \n+\t\"git new\" is equivalent to running the shell command \n+\t\"gitk --all --not ORIG_HEAD\".\n+\n apply.whitespace::\n \tTells `git-apply` how to handle whitespaces, in the same way\n \tas the '--whitespace' option. See gitlink:git-apply[1].\ndiff --git a/git.c b/git.c\nindex c43d4ff..2f10d50 100644\n--- a/git.c\n+++ b/git.c\n@@ -159,6 +159,16 @@ static int handle_alias(int *argcp, const char ***argv)\n \talias_command = (*argv)[0];\n \tgit_config(git_alias_config);\n \tif (alias_string) {\n+\t\tif (alias_string[0] == '!') {\n+\t\t\ttrace_printf(\"trace: alias to shell cmd: %s => %s\\n\",\n+\t\t\t\t     alias_command, alias_string + 1);\n+\t\t\tret = system(alias_string + 1);\n+\t\t\tif (ret >= 0 && WIFEXITED(ret) && \n+\t\t\t    WEXITSTATUS(ret) != 127)\n+\t\t\t\texit(WEXITSTATUS(ret));\n+\t\t\tdie(\"Failed to run '%s' when expanding alias '%s'\\n\", \n+\t\t\t    alias_string + 1, alias_command);\n+\t\t}\n \t\tcount = split_cmdline(alias_string, &new_argv);\n \t\toption_count = handle_options(&new_argv, &count);\n \t\tmemmove(new_argv - option_count, new_argv,\n-- \n1.5.0.rc4.2.g4249\n"},{"id":"34171","messageId":"Pine.LNX.4.63.0702111727110.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6764","inReplyTo":"11711540383470-git-send-email-tytso@mit.edu","subject":"Re: [PATCH 0/2] Respun patches for git aliases enhancement","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-11T16:32:23Z","receivedAt":"2007-02-11T16:32:23Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 10 Feb 2007, Theodore Ts'o wrote:\n\n> These patches have been respun to fix a spelling typo and in response\n> to comments from Johannes.\n\nSorry to have apply-checked only now: Ted, could you run the second commit \nthrough \"git show --check\"? It has 4 whitespaces at end. But I am sure \nthat Junio can fix them.\n\nApart from that:\nAcked-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nCiao,\nDscho\n"}]}