Skip to content

Commit

Permalink
Added support for worktrees
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorjonl committed Jan 13, 2017
1 parent 10cf47d commit 29e977b
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/GitInfo/build/GitInfo.targets
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,40 @@
repository. -->
<PropertyGroup>
<GitDir>$([System.IO.Path]::Combine('$(GitRoot)', '.git'))</GitDir>
<_IsGitSubmodule>$([System.IO.File]::Exists('$(GitDir)'))</_IsGitSubmodule>
<_IsGitFile>$([System.IO.File]::Exists('$(GitDir)'))</_IsGitFile>
</PropertyGroup>
<PropertyGroup Condition="'$(_IsGitSubmodule)' == 'true'">

<Exec Condition="'$(_IsGitFile)' == 'true'"
Command='$(GitExe) rev-parse --is-inside-work-tree'
StandardErrorImportance='high'
StandardOutputImportance='low'
ConsoleToMSBuild='true'
WorkingDirectory='$(GitInfoBaseDir)'
ContinueOnError='true'>
<Output TaskParameter="ConsoleOutput" PropertyName="_GitIsWorkTree"/>
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>

<PropertyGroup Condition="'$(MSBuildLastExitCode)' == '0'">
<_IsGetWorkTree>$(_GitIsWorkTree.Trim())</_IsGetWorkTree>
</PropertyGroup>

<Exec Condition="'$(_IsGitFile)' == 'true' and '$(_IsGetWorkTree)' == 'true'"
Command='$(GitExe) rev-parse --git-common-dir'
StandardErrorImportance='high'
StandardOutputImportance='low'
ConsoleToMSBuild='true'
WorkingDirectory='$(GitInfoBaseDir)'
ContinueOnError='true'>
<Output TaskParameter="ConsoleOutput" PropertyName="_GitCommonDir"/>
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>

<PropertyGroup Condition="'$(_IsGitFile)' == 'true' and '$(_IsGetWorkTree)' == 'true'">
<GitDir>$(_GitCommonDir)</GitDir>
</PropertyGroup>

<PropertyGroup Condition="'$(_IsGitFile)' == 'true' and '$(_IsGetWorkTree)' != 'true'">
<_GitFileContents>$([System.IO.File]::ReadAllText('$(GitDir)'))</_GitFileContents>
<GitDir>$([System.String]::new('$(_GitFileContents)').Substring(7).Trim())</GitDir>
<GitDir>$([System.IO.Path]::Combine('$(GitRoot)', '$(GitDir)'))</GitDir>
Expand Down

0 comments on commit 29e977b

Please sign in to comment.