Skip to content

Commit a94cefd

Browse files
committed
Properly detect branch changes for incremental builds
When the current HEAD (branch/tag/commit) is changed within VS, we currently don't surface any changes and the IDE thinks there's nothing to update. But obviously GitInfo would need to calculate again all the info. This commit takes the ideas from #186 by @brunom, integrates into GitInfo and surfaces it to VS seamlessly so users don't have to customize anything and it Just Works. Closes #186
1 parent 0b55393 commit a94cefd

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ Available [MSBuild properties](https://learn.microsoft.com/en-us/visualstudio/ms
235235
performance reasons.
236236
Defaults to empty value (no ignoring).
237237
238+
$(GitCachePath): where to cache the determined Git information
239+
gives the chance to use a shared location
240+
for different projects. this can improve
241+
the overall build time.
242+
has to end with a path seperator
243+
Defaults to empty value ('$(IntermediateOutputPath)').
244+
238245
$(GitNameRevOptions): Options passed to git name-rev when finding
239246
a branch name for the current commit (Detached head). The default is
240247
'--refs=refs/heads/* --no-undefined --alwas'

src/GitInfo/build/GitInfo.targets

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,27 @@
969969

970970
</Target>
971971

972+
<!-- This combination of prop/item/target fix incremental builds after HEAD changes. -->
973+
<PropertyGroup>
974+
<_GitCacheFullPath>$([System.IO.Path]::Combine($(MSBuildProjectDirectory), $(GitCachePath)))</_GitCacheFullPath>
975+
<!-- We read the path to the HEAD file, written in a previously run _GitWriteHeadPath target -->
976+
<_GitHeadPath Condition="Exists('$(_GitCacheFullPath)GitHead.cache')">$([System.IO.File]::ReadAllText('$(_GitCacheFullPath)GitHead.cache').Trim())</_GitHeadPath>
977+
</PropertyGroup>
978+
979+
<ItemGroup>
980+
<!-- And if the HEAD path exists, we add it as an input for the fast up-to-date check VS performs -->
981+
<UpToDateCheckInput Condition="'$(_GitHeadPath)' != '' and Exists('$(_GitHeadPath)')" Include="$(_GitHeadPath)" />
982+
</ItemGroup>
983+
984+
<!-- NOTE: we write the path to HEAD after first calculating a version, since we can be anywhere in
985+
the solution structure. This file will only be written if there's a change in the git root,
986+
which should never happen. -->
987+
<Target Name="_GitWriteHeadPath" AfterTargets="GitVersion">
988+
<WriteLinesToFile Lines="$(GitRoot).git\HEAD"
989+
File="$(GitCachePath)GitHead.cache"
990+
Overwrite="true" WriteOnlyWhenDifferent="true" />
991+
</Target>
992+
972993
<!--
973994
============================================================
974995
GitExe Property

0 commit comments

Comments
 (0)