technomancy/leiningen — pull request #782 by basicsensei (2012-09-13 07:59:46+00:00)
Title: move setlocal first to prevent leaking LEIN_VERSION to parent shell in win7/xp

since it's not leaked in bash scripts, as per this: https://github.com/technomancy/leiningen/pull/781#issuecomment-8518669

In Windows 7/Windows XP `cmd.exe` (tested):
I see that only `LEIN_VERSION` is leaked because it's before the `setlocal`.
`Start` > `Run` `cmd.exe` then `lein.bat` then `set` will show it set. No other variables should be leaked (because of that `setlocal`) **unless** the script fails:
ie. `set JAVA_CMD="ja"va"` then run `lein.bat` will yield `The syntax of the command is incorrect.` (in windows 7) and all the variables set so far in the batch are leaked such as `LEIN_HOME`, `LEIN_JAR` and `ORIGINAL_PWD` which aren't leaked when script didn't err.
The "**unless**" part is valid only for Windows 7(feature?), it doesn't leak in Windows XP. (tested), but even in Windows 7, the script fail must occur after another occurrence of `setlocal` and before its `endlocal` if any (ie. currently possible only inside the `:EnsureIsSet` procedure), else it will still not leak.

Can use this .bat to test the above:
```batch
@echo on
setLocal EnableExtensions EnableDelayedExpansion
set xxx="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

rem comment the following line to prevent xxx to leak into parent shell:
setlocal
rem uncomment the following line to see it won't leak(or uncomment&move it below fail to see it will):
rem endlocal
rem the below will make script fail(just type "set" to see it leaked):
if x == '

echo not reached!

```