git-wrapper: optionally skip cd $HOME when configured via resources

We recently added the ability to configure copies of the Git wrapper to
launch custom command-lines, configured via plain old Windows resources.
The main user is Git for Windows' `git-bash.exe`, of course. When the
user double-clicks the `git bash` icon, it makes sense to start the Bash
in the user's home directory.

Third-party software, such as TortoiseGit or GitHub for Windows, may
want to start the Git Bash in another directory, though.

Now, when third-party software wants to call Git, they already have to
construct a command-line, and can easily pass a command-line option
`--no-cd` (which this commit introduces), and since that option is not
available when the user double-clicks an icon on the Desktop or in the
Explorer, let's keep the default to switch to the home directory if the
`--no-cd` flag was not passed along.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2015-03-28 18:20:04 +01:00
parent 3fb3feb40d
commit 2e0e99ae9d

View File

@@ -163,7 +163,7 @@ static LPWSTR fixup_commandline(LPWSTR exepath, LPWSTR *exep, int *wait,
static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
LPWSTR *prefix_args, int *prefix_args_len,
int *is_git_command, int *start_in_home)
int *is_git_command, int *start_in_home, int *skip_arguments)
{
int id, wargc;
LPWSTR *wargv;
@@ -252,7 +252,14 @@ static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
*prefix_args_len = wcslen(buf);
*is_git_command = 0;
*start_in_home = 1;
wargv = CommandLineToArgvW(GetCommandLine(), &wargc);
if (wargc < 2 || wcscmp(L"--no-cd", wargv[1]))
*start_in_home = 1;
else {
*start_in_home = 0;
*skip_arguments = 1;
}
LocalFree(wargv);
return 1;
}
@@ -278,7 +285,7 @@ int main(void)
basename = exepath + wcslen(exepath) + 1;
if (configure_via_resource(basename, exepath, exep,
&prefix_args, &prefix_args_len,
&is_git_command, &start_in_home)) {
&is_git_command, &start_in_home, &skip_arguments)) {
/* do nothing */
}
else if (!wcsncmp(basename, L"git-", 4)) {