Skip to content

Commit

Permalink
Added support for worktrees
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorjonl authored and kzu committed Jan 27, 2017
1 parent 6695f98 commit 78dfc50
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'">
<_IsGitWorkTree>$(_GitIsWorkTree.Trim())</_IsGitWorkTree>
</PropertyGroup>

<Exec Condition="'$(_IsGitFile)' == 'true' and '$(_IsGitWorkTree)' == '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 '$(_IsGitWorkTree)' == 'true'">
<GitDir>$(_GitCommonDir)</GitDir>
</PropertyGroup>

<PropertyGroup Condition="'$(_IsGitFile)' == 'true' and '$(_IsGitWorkTree)' != '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 78dfc50

Please sign in to comment.