Skip to content

Commit ea02513

Browse files
asbjornuJakeGinnivan
authored andcommitted
Added VersionVariables.FromFile() method and corresponding FileName property and make use of it in VersionAndBranchFinderLoadVersionVariablesFromDiskCache().
1 parent 7284ed5 commit ea02513

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

src/GitVersionCore/OutputVariables/VersionVariables.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
using System;
44
using System.Collections;
55
using System.Collections.Generic;
6+
using System.IO;
67
using System.Linq;
78
using System.Reflection;
89

10+
using GitVersion.Helpers;
11+
12+
using YamlDotNet.Serialization;
13+
914
public class VersionVariables : IEnumerable<KeyValuePair<string, string>>
1015
{
1116
public static VersionVariables FromDictionary(IEnumerable<KeyValuePair<string, string>> properties)
@@ -104,6 +109,9 @@ public static IEnumerable<string> AvailableVariables
104109

105110
public string CommitDate { get; set; }
106111

112+
[ReflectionIgnore]
113+
public string FileName { get; set; }
114+
107115
[ReflectionIgnore]
108116
public string this[string variable]
109117
{
@@ -140,6 +148,21 @@ public static VersionVariables FromDictionary(IEnumerable<KeyValuePair<string, s
140148
}
141149

142150

151+
public static VersionVariables FromFile(string filePath, IFileSystem fileSystem)
152+
{
153+
using (var stream = fileSystem.OpenRead(filePath))
154+
{
155+
using (var reader = new StreamReader(stream))
156+
{
157+
var dictionary = new Deserializer().Deserialize<Dictionary<string, string>>(reader);
158+
var versionVariables = FromDictionary(dictionary);
159+
versionVariables.FileName = filePath;
160+
return versionVariables;
161+
}
162+
}
163+
}
164+
165+
143166
public bool TryGetValue(string variable, out string variableValue)
144167
{
145168
if (ContainsKey(variable))

src/GitVersionTask/VersionAndBranchFinder.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,7 @@ static VersionVariables LoadVersionVariablesFromDiskCache(string key, string dir
7373
{
7474
try
7575
{
76-
using (var stream = fileSystem.OpenRead(cacheFileName))
77-
{
78-
using (var reader = new StreamReader(stream))
79-
{
80-
var dictionary = new Deserializer().Deserialize<Dictionary<string, string>>(reader);
81-
vv = VersionVariables.FromDictionary(dictionary);
82-
}
83-
}
84-
76+
vv = VersionVariables.FromFile(cacheFileName, fileSystem);
8577
}
8678
catch (Exception ex)
8779
{
@@ -106,6 +98,7 @@ static VersionVariables LoadVersionVariablesFromDiskCache(string key, string dir
10698
if (vv == null)
10799
{
108100
vv = ExecuteCore.ExecuteGitVersion(fileSystem, null, null, authentication, null, noFetch, directory, null);
101+
vv.FileName = cacheFileName;
109102

110103
using (var stream = fileSystem.OpenWrite(cacheFileName))
111104
using (var sw = new StreamWriter(stream))

0 commit comments

Comments
 (0)