Skip to content

Commit 4766c3d

Browse files
committed
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 <[email protected]>
1 parent b072d68 commit 4766c3d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

compat/win32/git-wrapper.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static LPWSTR fixup_commandline(LPWSTR exepath, LPWSTR *exep, int *wait,
163163

164164
static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
165165
LPWSTR *prefix_args, int *prefix_args_len,
166-
int *is_git_command, int *start_in_home)
166+
int *is_git_command, int *start_in_home, int *skip_arguments)
167167
{
168168
int id = 0, wargc;
169169
LPWSTR *wargv;
@@ -255,7 +255,14 @@ static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
255255
*prefix_args_len = wcslen(buf);
256256

257257
*is_git_command = 0;
258-
*start_in_home = 1;
258+
wargv = CommandLineToArgvW(GetCommandLine(), &wargc);
259+
if (wargc < 2 || wcscmp(L"--no-cd", wargv[1]))
260+
*start_in_home = 1;
261+
else {
262+
*start_in_home = 0;
263+
*skip_arguments = 1;
264+
}
265+
LocalFree(wargv);
259266

260267
return 1;
261268
}
@@ -281,7 +288,7 @@ int main(void)
281288
basename = exepath + wcslen(exepath) + 1;
282289
if (configure_via_resource(basename, exepath, exep,
283290
&prefix_args, &prefix_args_len,
284-
&is_git_command, &start_in_home)) {
291+
&is_git_command, &start_in_home, &skip_arguments)) {
285292
/* do nothing */
286293
}
287294
else if (!wcsncmp(basename, L"git-", 4)) {

0 commit comments

Comments
 (0)