Skip to content

Commit eae6ec4

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 09af9bc commit eae6ec4

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, wargc;
169169
LPWSTR *wargv;
@@ -252,7 +252,14 @@ static int configure_via_resource(LPWSTR basename, LPWSTR exepath, LPWSTR exep,
252252
*prefix_args_len = wcslen(buf);
253253

254254
*is_git_command = 0;
255-
*start_in_home = 1;
255+
wargv = CommandLineToArgvW(GetCommandLine(), &wargc);
256+
if (wargc < 2 || wcscmp(L"--no-cd", wargv[1]))
257+
*start_in_home = 1;
258+
else {
259+
*start_in_home = 0;
260+
*skip_arguments = 1;
261+
}
262+
LocalFree(wargv);
256263

257264
return 1;
258265
}
@@ -278,7 +285,7 @@ int main(void)
278285
basename = exepath + wcslen(exepath) + 1;
279286
if (configure_via_resource(basename, exepath, exep,
280287
&prefix_args, &prefix_args_len,
281-
&is_git_command, &start_in_home)) {
288+
&is_git_command, &start_in_home, &skip_arguments)) {
282289
/* do nothing */
283290
}
284291
else if (!wcsncmp(basename, L"git-", 4)) {

0 commit comments

Comments
 (0)