Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only write files if they changed #242

Merged
merged 1 commit into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CSharpier.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpier.Benchmarks", "Src\CSharpier.Benchmarks\CSharpier.Benchmarks.csproj", "{A338903F-69AD-4950-B827-8EE75F98B620}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MSBuild", "MSBuild", "{A267B806-24B0-4F3E-B5C2-9481C98627D0}"
ProjectSection(SolutionItems) = preProject
Src\CSharpier.MsBuild\README.md = Src\CSharpier.MsBuild\README.md
Src\CSharpier.MsBuild\build\CSharpier.MsBuild.targets = Src\CSharpier.MsBuild\build\CSharpier.MsBuild.targets
Src\CSharpier.MsBuild\build\CSharpier.MsBuild.props = Src\CSharpier.MsBuild\build\CSharpier.MsBuild.props
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -73,5 +80,9 @@ Global
{A338903F-69AD-4950-B827-8EE75F98B620}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A338903F-69AD-4950-B827-8EE75F98B620}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A338903F-69AD-4950-B827-8EE75F98B620}.Release|Any CPU.Build.0 = Release|Any CPU
{3FE3D5DE-1284-45C6-95FC-8B3CDE63684B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3FE3D5DE-1284-45C6-95FC-8B3CDE63684B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3FE3D5DE-1284-45C6-95FC-8B3CDE63684B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3FE3D5DE-1284-45C6-95FC-8B3CDE63684B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
6 changes: 3 additions & 3 deletions Src/CSharpier.MsBuild/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
You can test this by doing
`dotnet pack -o publish`
Then add a nuget source pointing to that folder and install the nuget package into a project
You can test this by running the following from `Src/CSharpier.MSBuild`
`dotnet pack -o publish`
Then add a nuget source pointing to `\Src\CSharpier.MsBuild\publish` and install the nuget package into a project
7 changes: 5 additions & 2 deletions Src/CSharpier/CommandLineFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,11 @@ private async Task FormatFile(string file, CancellationToken cancellationToken)
cancellationToken.ThrowIfCancellationRequested();
Interlocked.Increment(ref this.Result.Files);

if (!this.CommandLineOptions.Check && !this.CommandLineOptions.SkipWrite)
{
if (
!this.CommandLineOptions.Check
&& !this.CommandLineOptions.SkipWrite
&& result.Code != fileReaderResult.FileContents
) {
// purposely avoid async here, that way the file completely writes if the process gets cancelled while running.
this.FileSystem.File.WriteAllText(file, result.Code, fileReaderResult.Encoding);
}
Expand Down