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

Commit

Permalink
Add fallback section for delayed expansion unavailability
Browse files Browse the repository at this point in the history
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 <send2adtc@gmail.com>
  • Loading branch information
ADTC committed Sep 15, 2014
1 parent a6018d3 commit c00ce10
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/gitk.cmd
@@ -1,5 +1,12 @@
@rem Do not use "echo off" to not affect any child calls.

@rem Enable extensions, the `verify other 2>nul` is a trick from the setlocal help
@verify other 2>nul
@setlocal enableDelayedExpansion
@if errorlevel 1 (
@echo Unable to enable delayed expansion. Immediate expansion will be used.
@goto fallback
)

@rem Get the absolute path to the parent directory, which is assumed to be the
@rem Git installation root.
Expand All @@ -10,3 +17,18 @@
@if not exist "!HOME!" @set HOME=!USERPROFILE!

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

:fallback
@rem The above script again with immediate expansion, in case delayed expansion
@rem is unavailable.
@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" -- %*

:end
@rem End of script

0 comments on commit c00ce10

Please sign in to comment.