Skip to content
This repository was archived by the owner on Apr 6, 2024. It is now read-only.

Commit b5dd7f5

Browse files
committed
Merge branch 'release/0.7.1'
2 parents 3359c25 + c6c5ad2 commit b5dd7f5

File tree

6 files changed

+83
-36
lines changed

6 files changed

+83
-36
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These owners will be the default owners for everything in the repo and
2+
# will be requested for review when someone opens a pull request.
3+
* @pascalberger

nuspec/nuget/Cake.Issues.GitRepository.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ See the Project Site for an overview of the whole ecosystem of addins for workin
2424
<repository type="git" url="https://github.com/cake-contrib/Cake.Issues.GitRepository.git"/>
2525
<copyright>Copyright © Pascal Berger</copyright>
2626
<tags>Cake Script Cake-Issues Cake-IssueProvider CodeAnalysis Linting Git</tags>
27-
<releaseNotes>https://github.com/cake-contrib/Cake.Issues.GitRepository/releases/tag/0.7.0</releaseNotes>
27+
<releaseNotes>https://github.com/cake-contrib/Cake.Issues.GitRepository/releases/tag/0.7.1</releaseNotes>
2828
</metadata>
2929
<files>
3030
<file src="netstandard2.0/Cake.Issues.GitRepository.dll" target="lib\netstandard2.0" />

src/Cake.Issues.GitRepository/Cake.Issues.GitRepository.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<Version>0.7.0</Version>
3434
</PackageReference>
3535
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers">
36-
<Version>2.9.3</Version>
36+
<Version>2.9.4</Version>
3737
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
3838
<PrivateAssets>all</PrivateAssets>
3939
</PackageReference>

src/Cake.Issues.GitRepository/GitRepositoryIssuesProvider.cs

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,15 @@ private IEnumerable<IIssue> CheckForBinaryFilesNotTrackedByLfs(IssueCommentForma
7878
}
7979

8080
var textFiles = this.GetTextFilesFromRepository();
81-
if (!textFiles.Any())
82-
{
83-
return new List<IIssue>();
84-
}
85-
86-
this.Log.Information("Determine binary files...");
87-
var binaryFiles = allFiles.Except(textFiles);
88-
this.Log.Information("Found {0} binary file(s)", binaryFiles.Count());
8981

82+
var binaryFiles = this.DetermineBinaryFiles(allFiles, textFiles);
9083
if (!binaryFiles.Any())
9184
{
9285
return new List<IIssue>();
9386
}
9487

95-
this.Log.Debug(string.Join(Environment.NewLine, binaryFiles));
96-
97-
this.Log.Information("Checking if binary files are tracked by LFS...");
9888
var lfsTrackedFiles = this.GetLfsTrackedFilesFromRepository();
99-
100-
var binaryFilesNotTrackedByLfs = binaryFiles.Except(lfsTrackedFiles);
101-
this.Log.Information("Found {0} binary file(s) not tracked by LFS", binaryFilesNotTrackedByLfs.Count());
89+
var binaryFilesNotTrackedByLfs = this.DetermineBinaryFilesNotTrackedWithLfs(binaryFiles, lfsTrackedFiles);
10290

10391
var result = new List<IIssue>();
10492
foreach (var file in binaryFilesNotTrackedByLfs)
@@ -137,22 +125,23 @@ private IEnumerable<IIssue> CheckForBinaryFilesNotTrackedByLfs(IssueCommentForma
137125
/// <returns>List of files in the repository.</returns>
138126
private IEnumerable<string> GetAllFilesFromRepository()
139127
{
128+
this.Log.Verbose("Reading all files from repository '{0}'...", this.Settings.RepositoryRoot);
129+
140130
var settings = new GitRunnerSettings
141131
{
142132
WorkingDirectory = this.Settings.RepositoryRoot,
143133
};
144134

145-
this.Log.Information("Reading all files from repository '{0}'...", this.Settings.RepositoryRoot);
146135
settings.Arguments.Clear();
147-
settings.Arguments.Add("ls-files");
148-
var allFiles = this.runner.RunCommand(settings);
136+
settings.Arguments.Add("ls-files -z");
137+
var allFiles = string.Join(string.Empty, this.runner.RunCommand(settings)).Split('\0').Where(x => !string.IsNullOrEmpty(x));
149138

150139
if (allFiles == null)
151140
{
152141
throw new Exception("Error reading files from repository");
153142
}
154143

155-
this.Log.Information("Found {0} file(s)", allFiles.Count());
144+
this.Log.Verbose("Found {0} file(s)", allFiles.Count());
156145

157146
return allFiles;
158147
}
@@ -163,12 +152,13 @@ private IEnumerable<string> GetAllFilesFromRepository()
163152
/// <returns>List of text files in the repository.</returns>
164153
private IEnumerable<string> GetTextFilesFromRepository()
165154
{
155+
this.Log.Verbose("Reading all text files from repository '{0}'...", this.Settings.RepositoryRoot);
156+
166157
var settings = new GitRunnerSettings
167158
{
168159
WorkingDirectory = this.Settings.RepositoryRoot,
169160
};
170161

171-
this.Log.Information("Reading all text files from repository '{0}'...", this.Settings.RepositoryRoot);
172162
settings.Arguments.Clear();
173163
settings.Arguments.Add("grep -Il .");
174164
var textFiles = this.runner.RunCommand(settings);
@@ -177,7 +167,7 @@ private IEnumerable<string> GetTextFilesFromRepository()
177167
throw new Exception("Error reading text files from repository");
178168
}
179169

180-
this.Log.Information("Found {0} text file(s)", textFiles.Count());
170+
this.Log.Verbose("Found {0} text file(s)", textFiles.Count());
181171

182172
return textFiles;
183173
}
@@ -188,23 +178,68 @@ private IEnumerable<string> GetTextFilesFromRepository()
188178
/// <returns>List of files tracked by Git LFS.</returns>
189179
private IEnumerable<string> GetLfsTrackedFilesFromRepository()
190180
{
181+
this.Log.Verbose("Reading all LFS tracked files from repository '{0}'...", this.Settings.RepositoryRoot);
182+
191183
var settings = new GitRunnerSettings
192184
{
193185
WorkingDirectory = this.Settings.RepositoryRoot,
194186
};
195187

196-
this.Log.Information("Reading all LFS tracked files from repository '{0}'...", this.Settings.RepositoryRoot);
197188
settings.Arguments.Clear();
198-
settings.Arguments.Add("lfs ls-files");
189+
settings.Arguments.Add("lfs ls-files -n");
199190
var lfsTrackedFiles = this.runner.RunCommand(settings);
200191
if (lfsTrackedFiles == null)
201192
{
202193
throw new Exception("Error reading LFS tracked files from repository");
203194
}
204195

205-
this.Log.Information("Found {0} LFS tracked file(s)", lfsTrackedFiles.Count());
196+
this.Log.Verbose("Found {0} LFS tracked file(s)", lfsTrackedFiles.Count());
206197

207198
return lfsTrackedFiles;
208199
}
200+
201+
/// <summary>
202+
/// Determines binary files.
203+
/// </summary>
204+
/// <param name="allFiles">List of all files in the repository.</param>
205+
/// <param name="textFiles">List of text files in the repository.</param>
206+
/// <returns>List of binary files in the repository.</returns>
207+
private IEnumerable<string> DetermineBinaryFiles(IEnumerable<string> allFiles, IEnumerable<string> textFiles)
208+
{
209+
this.Log.Verbose("Determine binary files...");
210+
211+
var binaryFiles = allFiles.Except(textFiles);
212+
213+
if (binaryFiles.Any())
214+
{
215+
this.Log.Debug(string.Join(Environment.NewLine, binaryFiles));
216+
}
217+
218+
this.Log.Verbose("Found {0} binary file(s)", binaryFiles.Count());
219+
220+
return binaryFiles;
221+
}
222+
223+
/// <summary>
224+
/// Determines binary files which are not tracked with LFS.
225+
/// </summary>
226+
/// <param name="binaryFiles">List of binary files in the repository.</param>
227+
/// <param name="lfsTrackedFiles">List of files tracked with LFS in the repository.</param>
228+
/// <returns>List of binary files in the repository which are not tracked with LFS.</returns>
229+
private IEnumerable<string> DetermineBinaryFilesNotTrackedWithLfs(IEnumerable<string> binaryFiles, IEnumerable<string> lfsTrackedFiles)
230+
{
231+
this.Log.Verbose("Checking if binary files are tracked by LFS...");
232+
233+
var binaryFilesNotTrackedWithLfs = binaryFiles.Except(lfsTrackedFiles);
234+
235+
if (binaryFilesNotTrackedWithLfs.Any())
236+
{
237+
this.Log.Debug(string.Join(Environment.NewLine, binaryFilesNotTrackedWithLfs));
238+
}
239+
240+
this.Log.Verbose("Found {0} binary file(s) not tracked by LFS", binaryFilesNotTrackedWithLfs.Count());
241+
242+
return binaryFilesNotTrackedWithLfs;
243+
}
209244
}
210245
}

src/Cake.Issues.GitRepository/GitRunner.cs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Linq;
6+
using System.Text;
67
using Cake.Core;
78
using Cake.Core.IO;
89
using Cake.Core.Tooling;
@@ -50,17 +51,25 @@ public IEnumerable<string> RunCommand(GitRunnerSettings settings)
5051
RedirectStandardOutput = true,
5152
};
5253

53-
IEnumerable<string> result = null;
54-
this.Run(
55-
settings,
56-
null,
57-
processSettings,
58-
process =>
59-
{
60-
result = process.GetStandardOutput();
61-
});
62-
63-
return result?.ToList();
54+
var currentEncoding = Console.OutputEncoding;
55+
Console.OutputEncoding = Encoding.UTF8;
56+
try
57+
{
58+
IEnumerable<string> result = null;
59+
this.Run(
60+
settings,
61+
null,
62+
processSettings,
63+
process =>
64+
{
65+
result = process.GetStandardOutput();
66+
});
67+
return result?.ToList();
68+
}
69+
finally
70+
{
71+
Console.OutputEncoding = currentEncoding;
72+
}
6473
}
6574

6675
/// <summary>
3.44 KB
Loading

0 commit comments

Comments
 (0)