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

Fix gitk.cmd to work correctly when paths contain ampersand (&) symbol - #252

Merged
dscho merged 2 commits into
msysgit:masterfrom
ADTC:master
Sep 15, 2014
Merged

dscho merged 2 commits into
msysgit:masterfrom
ADTC:master

Conversation

@ADTC

@ADTC ADTC commented Sep 15, 2014

Copy link
Copy Markdown
Contributor

This is to fix the issue msysgit/git#245 I reported previously.

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.

I have also enhanced the script to fall back to the original script code when delayed expansion is not available on the target computer system (in which case, a path containing ampersand may still cause the script to fail).

With the immediate expansion, paths containing the ampersand symbol (&)
will not work in this script. This is likely to occur when the user
profile is located in a folder that contains the symbol in its name.
The command processor misinterprets the symbol as to mean the union of
two separate commands.

To avoid the issue, "delayed expansion" is used and the environment
variables are demarcated using the exclamation mark (!) instead of
the percentage symbol (%).

Signed-off-by: ADTC <[email protected]>
Taking cue from start-ssh-agent.cmd, enhanced gitk.cmd to fallback to
the immediate expansion script if delayed expansion is unavailable.

Both script sections are the same, except for the different environment
variable delimiters. When new changes are made, both sections must be
updated correctly, taking care to use the correct delimiter (! or %) to
demarcate the environment variables. (In fact, the fallback section is
exactly the same as the original script before previous commit.)

Signed-off-by: ADTC <[email protected]>
dscho added a commit that referenced this pull request Sep 15, 2014
Fix gitk.cmd to work correctly when paths contain ampersand (&) symbol
@dscho
dscho merged commit 438f29b into msysgit:master Sep 15, 2014
@dscho

dscho commented Sep 15, 2014

Copy link
Copy Markdown
Member

Thank you so much for your contribution. This PR was truly a pleasure to review!

@ADTC

ADTC commented Sep 15, 2014

Copy link
Copy Markdown
Contributor Author

Don't mention it :) I should thank you! 👍 The pleasure is all mine. I actually love writing good commit messages, and this has been a rewarding experience for me. And certainly learnt about proper contributor crediting :)

Btw, I didn't look for any documentation about the "Signed-off-by:" line. I just followed the messages of the previous commits in the project. Hope I got it right.

@dscho

dscho commented Sep 15, 2014

Copy link
Copy Markdown
Member

Btw, I didn't look for any documentation about the "Signed-off-by:" line. I just followed the messages of the previous commits in the project. Hope I got it right.

Yep, you got it right!

The meaning of those lines is a little bit important, though: you state that you are allowed to contribute this work into Open Source (i.e. if you did this work on your employer's time, you have to be certain that it is okay to release the code into the open).

@GiantDarth

Copy link
Copy Markdown

Is this unrelated to the fix I already made with Git-Cheetah? msysgit/Git-Cheetah#17

@dscho

dscho commented Oct 8, 2014

Copy link
Copy Markdown
Member

@chaos7theory yep, it is unrelated. This here PR is about gitk.cmd, i.e. the gitk that users get when they call it from the regular Windows command line. Your PR was about the Explorer integration. So while the underlying problems are related, the fixes are pretty different (the latter PR requires C – which I speak pretty fluently – while this here PR requires knowledge in Windows scripting – at which I suck).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants