@matheusbsbs / matheus-bagliano / commits / a2f8028d3d
Fork 0

Make '!' aliases more useful

When an alias starts with an exclamation mark, the rest is interpreted as a shell command. However, all arguments passed to git used to be ignored. Now you can have an alias like $ git config alias.e '!echo' and $ git e Hello World does what you expect it to do. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jul 1, 2007 at 22:51 UTC a2f8028d3d661b314d5a784764f2f5f9e4c2dde0
1 file changed +15
git.c
+15
@@ -181,6 +181,21 @@ static int handle_alias(int *argcp, const char ***argv)
181 git_config(git_alias_config);
182 if (alias_string) {
183 if (alias_string[0] == '!') {
184 + if (*argcp > 1) {
185 + int i, sz = PATH_MAX;
186 + char *s = xmalloc(sz), *new_alias = s;
187 +
188 + add_to_string(&s, &sz, alias_string, 0);
189 + free(alias_string);
190 + alias_string = new_alias;
191 + for (i = 1; i < *argcp &&
192 + !add_to_string(&s, &sz, " ", 0) &&
193 + !add_to_string(&s, &sz, (*argv)[i], 1)
194 + ; i++)
195 + ; /* do nothing */
196 + if (!sz)
197 + die("Too many or long arguments");
198 + }
199 trace_printf("trace: alias to shell cmd: %s => %s\n",
200 alias_command, alias_string + 1);
201 ret = system(alias_string + 1);