msysgit / git

msysGit-based Git for Windows 1.x is now superseded by Git for Windows 2.x
http://github.com/git-for-windows/git
Other
1.01k stars 317 forks source link

gitk.cmd fails when user profile folder name has ampersand symbol #245

Closed ADTC closed 10 years ago

ADTC commented 10 years ago

Assume the user profile is in C:\Users\A&E\.

The gitk.cmd script will fail in this case because & is recognized as joining two commands in a batch script, unless if the path is double quoted.

The easiest fix for this is to use "delayed expansion" coupled with ! (instead of %) to demarcate the environment variable names.

Fixed script:

@rem Do not use "echo off" to not affect any child calls.
@setlocal enableDelayedExpansion

@rem Get the absolute path to the parent directory, which is assumed to be the
@rem Git installation root.
@for /F "delims=" %%I in ("%~dp0..") do @set git_install_root=%%~fI
@set PATH=!git_install_root!\bin;!git_install_root!\mingw\bin;!PATH!

@if not exist "!HOME!" @set HOME=!HOMEDRIVE!!HOMEPATH!
@if not exist "!HOME!" @set HOME=!USERPROFILE!

@start "gitk" wish.exe "!git_install_root!\bin\gitk" -- %*

Original script:

@rem Do not use "echo off" to not affect any child calls.
@setlocal

@rem Get the absolute path to the parent directory, which is assumed to be the
@rem Git installation root.
@for /F "delims=" %%I in ("%~dp0..") do @set git_install_root=%%~fI
@set PATH=%git_install_root%\bin;%git_install_root%\mingw\bin;%PATH%

@if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%
@if not exist "%HOME%" @set HOME=%USERPROFILE%

@start "gitk" wish.exe "%git_install_root%\bin\gitk" -- %*

Related Stack Overflow question for more information (Disclaimer: posted by me)

sschuberth commented 10 years ago

Thanks. Would you mind making a pull request out of this?

ADTC commented 10 years ago

I didn't feel like forking the project just for this one-off fix, but since you insist I will :) :+1:

sschuberth commented 10 years ago

Thanks. This is not about laziness BTW, but also about things like maintaining correct authorship and giving proper credit.

ADTC commented 10 years ago

I understand. Unfortunately I cannot find gitk.cmd in the repository. Am I looking at the wrong repo?

sschuberth commented 10 years ago

Probably. As that file is not strictly related to the pure port of Git to Windows, but a convenience tool, it's in msysgit/msysgit.

dscho commented 10 years ago

This is not about laziness BTW, but also about things like maintaining correct authorship and giving proper credit.

Well, not to forget about the respect and gratitude to contribute back to a project that lives on contributions. Never forget that this project is built on a great community, and you have the opportunity to be part of that community. By contributing.