Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

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

Description

@ADTC

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)

Activity

  1. sschuberth commented on Sep 14, 2014

    @sschuberth

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

  2. ADTC commented on Sep 14, 2014

    @ADTC
    Author

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

  3. sschuberth commented on Sep 14, 2014

    @sschuberth

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

  4. ADTC commented on Sep 14, 2014

    @ADTC
    Author

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

  5. sschuberth commented on Sep 14, 2014

    @sschuberth

    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.

  6. dscho commented on Sep 14, 2014

    @dscho
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions