| 366 | } |
| 367 | |
| 368 | static int handle_alias(struct strvec *args, struct string_list *expanded_aliases) |
| 369 | { |
| 370 | int envchanged = 0, ret = 0, saved_errno = errno; |
| 371 | int count, option_count; |
| 372 | const char **new_argv; |
| 373 | const char *alias_command; |
| 374 | char *alias_string; |
| 375 | |
| 376 | alias_command = args->v[0]; |
| 377 | alias_string = alias_lookup(alias_command); |
| 378 | if (alias_string) { |
| 379 | struct string_list_item *seen; |
| 380 | |
| 381 | if (args->nr == 2 && !strcmp(args->v[1], "-h")) |
| 382 | fprintf_ln(stderr, _("'%s' is aliased to '%s'"), |
| 383 | alias_command, alias_string); |
| 384 | if (alias_string[0] == '!') { |
| 385 | struct child_process child = CHILD_PROCESS_INIT; |
| 386 | int nongit_ok; |
| 387 | |
| 388 | /* Aliases expect GIT_PREFIX, GIT_DIR etc to be set */ |
| 389 | setup_git_directory_gently(the_repository, &nongit_ok); |
| 390 | |
| 391 | commit_pager_choice(); |
| 392 | |
| 393 | child.use_shell = 1; |
| 394 | child.clean_on_exit = 1; |
| 395 | child.wait_after_clean = 1; |
| 396 | child.trace2_child_class = "shell_alias"; |
| 397 | strvec_push(&child.args, alias_string + 1); |
| 398 | strvec_pushv(&child.args, args->v + 1); |
| 399 | |
| 400 | trace2_cmd_alias(alias_command, child.args.v); |
| 401 | trace2_cmd_name("_run_shell_alias_"); |
| 402 | |
| 403 | ret = run_command(&child); |
| 404 | if (ret >= 0) /* normal exit */ |
| 405 | exit(ret); |
| 406 | |
| 407 | die_errno(_("while expanding alias '%s': '%s'"), |
| 408 | alias_command, alias_string + 1); |
| 409 | } |
| 410 | count = split_cmdline(alias_string, &new_argv); |
| 411 | if (count < 0) |
| 412 | die(_("bad alias.%s string: %s"), alias_command, |
| 413 | _(split_cmdline_strerror(count))); |
| 414 | option_count = handle_options(&new_argv, &count, &envchanged); |
| 415 | if (envchanged) |
| 416 | die(_("alias '%s' changes environment variables.\n" |
| 417 | "You can use '!git' in the alias to do this"), |
| 418 | alias_command); |
| 419 | MOVE_ARRAY(new_argv - option_count, new_argv, count); |
| 420 | new_argv -= option_count; |
| 421 | |
| 422 | if (count < 1) |
| 423 | die(_("empty alias for %s"), alias_command); |
| 424 | |
| 425 | if (!strcmp(alias_command, new_argv[0])) |
no test coverage detected