Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for git in WSL #31

Merged
merged 4 commits into from
Apr 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/GitInfo/GitInfo.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ The generated code contains only constants, so it can be used to construct your
<file src="build\GitInfo.vb.pp" target="build" />
<file src="build\GitInfo.targets" target="build" />
<file src="build\GitInfo.xbuild" target="build" />
<file src="build\wslrun.cmd" target="build" />
<file src="build\wslpath.cmd" target="build" />
</files>
</package>
31 changes: 29 additions & 2 deletions src/GitInfo/build/GitInfo.targets
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
<GitRoot>$(_GitOutput.Trim())</GitRoot>
</PropertyGroup>

<!-- Account for cygwin separately -->
<!-- Account for cygwin/WSL separately -->
<Exec Command='"$(CygPathExe)" -w "$(_GitOutput)"'
WorkingDirectory="$(GitInfoBaseDir)"
StandardErrorImportance='high'
Expand Down Expand Up @@ -389,13 +389,25 @@
Condition="'$(IsValidGitBaseVersion)' == 'False'" />

<PropertyGroup>
<_GitVersionFile>$(GitVersionFile)</_GitVersionFile>
<GitBaseVersionSource>$(GitVersionFile)</GitBaseVersionSource>
<GitSemVerSource>File</GitSemVerSource>
</PropertyGroup>

<Message Text="Using base version from version file $(GitVersionFile)'" Importance="normal" />

<Exec Command='$(GitExe) log -n 1 --format=format:$(_ShortShaFormat) "$(GitVersionFile)"'
<!-- Account for cygwin/WSL separately -->
<Exec Command='"$(CygPathExe)" -u "$(_GitVersionFile)"'
WorkingDirectory="$(GitRoot)"
StandardErrorImportance='high'
StandardOutputImportance='low'
ConsoleToMSBuild='true'
Condition="'$(MSBuildLastExitCode)' == '0' And '$(CygPathExe)' != ''">
<Output TaskParameter="ConsoleOutput" PropertyName="_GitVersionFile" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>

<Exec Command='$(GitExe) log -n 1 --format=format:$(_ShortShaFormat) "$(_GitVersionFile)"'
StandardErrorImportance="low"
StandardOutputImportance="low"
ConsoleToMSBuild="true"
Expand All @@ -415,6 +427,17 @@
<_GitCommitsRelativeTo Condition="'$([System.IO.Path]::GetDirectoryName($(GitVersionFile)))' != ''">"$([System.IO.Path]::GetDirectoryName("$(GitVersionFile)"))"</_GitCommitsRelativeTo>
</PropertyGroup>

<!-- Account for cygwin/WSL separately -->
<Exec Command='"$(CygPathExe)" -u $(_GitCommitsRelativeTo)'
WorkingDirectory="$(GitRoot)"
StandardErrorImportance='high'
StandardOutputImportance='low'
ConsoleToMSBuild='true'
Condition="'$(MSBuildLastExitCode)' == '0' And '$(CygPathExe)' != '' And '$(_GitCommitsRelativeTo)' != ''">
<Output TaskParameter="ConsoleOutput" PropertyName="_GitCommitsRelativeTo" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>

<Exec Command='$(GitExe) rev-list --count --full-history "$(_GitLastBump)"..HEAD $(_GitCommitsRelativeTo)'
Condition="$(MSBuildLastExitCode) == '0' And '$(_GitLastBump)' != ''"
StandardErrorImportance="low"
Expand Down Expand Up @@ -786,7 +809,9 @@
<GitExe Condition="'$(GitExe)' == '' And Exists('C:\Program Files\Git\bin\git.exe')">"C:\Program Files\Git\bin\git.exe"</GitExe>
<GitExe Condition="'$(GitExe)' == '' And Exists('C:\Program Files (x86)\Git\bin\git.exe')">"C:\Program Files (x86)\Git\bin\git.exe"</GitExe>
<GitExe Condition="'$(GitExe)' == '' And Exists('C:\msysgit\bin\git.exe')">C:\msysgit\bin\git.exe</GitExe>
<GitExe Condition="'$(GitExe)' == '' And Exists('$(LOCALAPPDATA)\lxss\rootfs\usr\bin\git')">$(MSBuildThisFileDirectory)wslrun.cmd git</GitExe>
<GitExe Condition="'$(GitExe)' == '' And Exists('C:\cygwin\bin\git.exe')">C:\cygwin\bin\git.exe</GitExe>
<GitExe Condition="'$(GitExe)' == '' And Exists('C:\cygwin64\bin\git.exe')">C:\cygwin64\bin\git.exe</GitExe>
<!-- Ultimately, just try the exe and hope it exists in the PATH already -->
<GitExe Condition="'$(GitExe)' == ''">git.exe</GitExe>
</PropertyGroup>
Expand All @@ -804,7 +829,9 @@
============================================================
-->
<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
<CygPathExe Condition="'$(CygPathExe)' == '' And Exists('$(LOCALAPPDATA)\lxss\rootfs\usr\bin\git') And $(GitExe.Contains('wslrun.cmd'))">$(MSBuildThisFileDirectory)wslpath.cmd</CygPathExe>
<CygPathExe Condition="'$(CygPathExe)' == '' And Exists('C:\cygwin\bin\cygpath.exe') And $(GitExe.Contains('cygwin'))">C:\cygwin\bin\cygpath.exe</CygPathExe>
<CygPathExe Condition="'$(CygPathExe)' == '' And Exists('C:\cygwin64\bin\cygpath.exe') And $(GitExe.Contains('cygwin64'))">C:\cygwin64\bin\cygpath.exe</CygPathExe>
</PropertyGroup>

<Import Project="GitInfo.xbuild" Condition="'$(MSBuildRuntimeVersion)' == ''" />
Expand Down
26 changes: 26 additions & 0 deletions src/GitInfo/build/wslpath.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@echo off
setlocal EnableExtensions EnableDelayedExpansion
REM Usage: wslpath.cmd -w <linux path>
REM Converts a path from the Linux /mnt/c/... format into Windows format.

REM Usage: wslpath.cmd -u <windows path>
REM Converts a path from Windows to Linux format.

REM Both usages require `wslrun.cmd` in the same directory as this file.

if exist %0\..\wslrun.cmd set WSLRUN="%0\..\wslrun.cmd"
if exist %CD%\%0\..\wslrun.cmd set WSLRUN="%CD%\%0\..\wslrun.cmd"

if "%1" == "-w" goto :towindows
if "%1" == "-u" shift /1

REM Convert path to Linux
if exist "%1\*" (pushd %1) else (pushd %~dp1)
if ERRORLEVEL 1 goto :eof
%WSLRUN% pwd
popd
goto :eof

:towindows
REM Convert path to Windows
%WSLRUN% cd "'%2'" ^&^& cmd.exe /c cd
11 changes: 11 additions & 0 deletions src/GitInfo/build/wslrun.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@echo off
REM Usage: wslrun.cmd <bash command>
REM Runs the given command in the Windows Subsystem for Linux bash shell.

REM Locate bash.exe
REM 32/64 bits causes issues here because it actually redirects the System32 dir
set BASH=bash.exe
if exist C:\Windows\System32\bash.exe set BASH=C:\Windows\System32\bash.exe
if exist C:\Windows\Sysnative\bash.exe set BASH=C:\Windows\Sysnative\bash.exe

%BASH% -c "%*"