git.c: allow alias expansion without a git directory
With this, the configuration mechanism can be used to say: [alias] init = init-db --template=/path/to/template Signed-off-by: Matthias Lederhofer <matled@gmx.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
committed by
Junio C Hamano
parent
41e95f6990
commit
0347a8c764
10
git.c
10
git.c
@ -156,16 +156,14 @@ static int handle_alias(int *argcp, const char ***argv)
|
|||||||
{
|
{
|
||||||
int nongit = 0, ret = 0, saved_errno = errno;
|
int nongit = 0, ret = 0, saved_errno = errno;
|
||||||
const char *subdir;
|
const char *subdir;
|
||||||
|
|
||||||
subdir = setup_git_directory_gently(&nongit);
|
|
||||||
if (!nongit) {
|
|
||||||
int count, option_count;
|
int count, option_count;
|
||||||
const char** new_argv;
|
const char** new_argv;
|
||||||
|
|
||||||
|
subdir = setup_git_directory_gently(&nongit);
|
||||||
|
|
||||||
alias_command = (*argv)[0];
|
alias_command = (*argv)[0];
|
||||||
git_config(git_alias_config);
|
git_config(git_alias_config);
|
||||||
if (alias_string) {
|
if (alias_string) {
|
||||||
|
|
||||||
count = split_cmdline(alias_string, &new_argv);
|
count = split_cmdline(alias_string, &new_argv);
|
||||||
option_count = handle_options(&new_argv, &count);
|
option_count = handle_options(&new_argv, &count);
|
||||||
memmove(new_argv - option_count, new_argv,
|
memmove(new_argv - option_count, new_argv,
|
||||||
@ -193,8 +191,7 @@ static int handle_alias(int *argcp, const char ***argv)
|
|||||||
new_argv = realloc(new_argv, sizeof(char*) *
|
new_argv = realloc(new_argv, sizeof(char*) *
|
||||||
(count + *argcp + 1));
|
(count + *argcp + 1));
|
||||||
/* insert after command name */
|
/* insert after command name */
|
||||||
memcpy(new_argv + count, *argv + 1,
|
memcpy(new_argv + count, *argv + 1, sizeof(char*) * *argcp);
|
||||||
sizeof(char*) * *argcp);
|
|
||||||
new_argv[count+*argcp] = NULL;
|
new_argv[count+*argcp] = NULL;
|
||||||
|
|
||||||
*argv = new_argv;
|
*argv = new_argv;
|
||||||
@ -202,7 +199,6 @@ static int handle_alias(int *argcp, const char ***argv)
|
|||||||
|
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (subdir)
|
if (subdir)
|
||||||
chdir(subdir);
|
chdir(subdir);
|
||||||
|
|||||||
Reference in New Issue
Block a user