From 1c6d51beba01843ab4cf3a610bb143180f85288b Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 18 Jun 2009 21:06:17 +0200 Subject: [PATCH] Properly fix the 'cd $HOME' issue When starting the Git Bash or Git GUI from the start menu or a quick launch icon, we would like it to change the current working directory to the user home, but at the same time, the shell should _not_ change the current working directory when called from somewhere else. Unfortunately, we cannot call bash without --login, and there is simply no way to pass an option via the command line with that option, and we cannot modify the environment in .lnk files. But what we actually want to do is to set the current working directory, which _can_ be done from .lnk files, even to paths specified by environment variables. So let's just set the current working directory to %HOMEDRIVE%%HOMEPATH%. This is a slight change in behavior: if the user set the environment variable HOME to something different, the initial current working directory will not be what HOME says. We'll just have to live with that. Thanks go to Sebastian Schuberth for help with the InnoSetup installer and Heiko Voigt for pushing the issue forward. Signed-off-by: Johannes Schindelin --- etc/profile | 6 ------ share/WinGit/install.iss | 10 +++++----- share/msysGit/add-shortcut.tcl | 2 +- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/etc/profile b/etc/profile index 5b12e0b0..94bb56c8 100644 --- a/etc/profile +++ b/etc/profile @@ -109,12 +109,6 @@ $MESSAGE EOF } -# when called from "Git Bash Here", there is a "!C:=..." or similar in env -if ! env | grep -q '^!' -then - cd "$HOME" -fi - # let's make sure that the post-checkout hook is installed test -d /.git && test ! -x /.git/hooks/post-checkout && test -x /share/msysGit/post-checkout-hook && diff --git a/share/WinGit/install.iss b/share/WinGit/install.iss index 18d43c66..00b3e4cd 100644 --- a/share/WinGit/install.iss +++ b/share/WinGit/install.iss @@ -39,11 +39,11 @@ Source: "*"; DestDir: "{app}"; Excludes: "\*.bmp, gpl-2.0.rtf, \install.*, \tmp. Source: ReleaseNotes.rtf; DestDir: "{app}"; Flags: isreadme replacesameversion [Icons] -Name: "{group}\Git GUI"; Filename: "{app}\bin\wish.exe"; Parameters: """{app}\libexec\git-core\git-gui"""; WorkingDir: "%USERPROFILE%"; IconFilename: "{app}\etc\git.ico" -Name: "{group}\Git Bash"; Filename: "{syswow64}\cmd.exe"; Parameters: "/c """"{app}\bin\sh.exe"" --login -i"""; WorkingDir: "%USERPROFILE%"; IconFilename: "{app}\etc\git.ico" +Name: "{group}\Git GUI"; Filename: "{app}\bin\wish.exe"; Parameters: """{app}\libexec\git-core\git-gui"""; WorkingDir: "%HOMEDRIVE%%HOMEPATH%"; IconFilename: "{app}\etc\git.ico" +Name: "{group}\Git Bash"; Filename: "{syswow64}\cmd.exe"; Parameters: "/c """"{app}\bin\sh.exe"" --login -i"""; WorkingDir: "%HOMEDRIVE%%HOMEPATH%"; IconFilename: "{app}\etc\git.ico" Name: "{group}\Uninstall Git"; Filename: "{uninstallexe}" -Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\Git Bash"; Filename: "{syswow64}\cmd.exe"; Parameters: "/c """"{app}\bin\sh.exe"" --login -i"""; WorkingDir: "%USERPROFILE%"; IconFilename: "{app}\etc\git.ico"; Tasks: quicklaunchicon -Name: "{code:GetShellFolder|desktop}\Git Bash"; Filename: "{syswow64}\cmd.exe"; Parameters: "/c """"{app}\bin\sh.exe"" --login -i"""; WorkingDir: "%USERPROFILE%"; IconFilename: "{app}\etc\git.ico"; Tasks: desktopicon +Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\Git Bash"; Filename: "{syswow64}\cmd.exe"; Parameters: "/c """"{app}\bin\sh.exe"" --login -i"""; WorkingDir: "%HOMEDRIVE%%HOMEPATH%"; IconFilename: "{app}\etc\git.ico"; Tasks: quicklaunchicon +Name: "{code:GetShellFolder|desktop}\Git Bash"; Filename: "{syswow64}\cmd.exe"; Parameters: "/c """"{app}\bin\sh.exe"" --login -i"""; WorkingDir: "%HOMEDRIVE%%HOMEPATH%"; IconFilename: "{app}\etc\git.ico"; Tasks: desktopicon [Messages] BeveledLabel={#emit APP_URL} @@ -748,7 +748,7 @@ begin i:=GetArrayLength(EnvHome); if (i=0) or ((i=1) and (Length(EnvHome[0])=0)) then begin SetArrayLength(EnvHome,1); - EnvHome[0]:=ExpandConstant('{%USERPROFILE}'); + EnvHome[0]:=ExpandConstant('{%HOMEDRIVE}{%HOMEPATH}'); if not SetEnvStrings('HOME',IsAdminLoggedOn,True,EnvHome) then begin Msg:='Line {#emit __LINE__}: Unable to set the HOME environment variable.'; MsgBox(Msg,mbError,MB_OK); diff --git a/share/msysGit/add-shortcut.tcl b/share/msysGit/add-shortcut.tcl index 06389a0c..5e5247c4 100644 --- a/share/msysGit/add-shortcut.tcl +++ b/share/msysGit/add-shortcut.tcl @@ -79,7 +79,7 @@ exec make set binDirectory "$msysRoot/bin" set resDirectory "$msysRoot/share/resources" -exec ./create-shortcut.exe --work-dir "$binDirectory" \ +exec ./create-shortcut.exe --work-dir "%HOMEDRIVE%%HOMEPATH%" \ --icon-file "$resDirectory/msysgitlogo.ico" \ --arguments "--login -i" \ "$binDirectory/sh.exe" \ -- 2.11.4.GIT