Open martinsuchan opened 4 years ago
@JoeRobich can the user use a response file in this scenario?
Users can use a rsp file or file globbing to help in this situation. This is an example rsp which we use during CI for validating our own formatting. It would be invoked like dotnet format @validate.rsp
The main use case why I created this feature request is the idea to use dotnet-format for checking codestyle on CI/CD machine in Merge requests or single commits.
Using this command it is possible to get the list of all changed/added files in the last commit:
git diff --name-only HEAD HEAD~1
The goal is then forwarding output from this command into dotnet-format with the --check
flag.
In case of large refactorings or deeply nested source files with long relative paths it is easily possible to reach the maximum command length limit. This could be easily solved by using --includeList
(or similar argument) and file with filenames.
@martinsuchan Locally I ran git diff --name-only HEAD HEAD~1 > TestInclude.rsp
followed by dotnet format -f --check -v diag --include @TestInclude.rsp
. I think it should do the trick for you.
MachineName:format joeyrobichaud$ dotnet format -f --check -v diag --include @TestInclude.rsp
The dotnet CLI version is '5.0.100-preview.6.20277.3'.
Using MSBuild.exe located in '/usr/local/share/dotnet/sdk/5.0.100-preview.6.20277.3/'.
Formatting code files in workspace '/Users/joeyrobichaud/Source/format'.
Loading workspace.
Complete in 1074ms.
Determining formattable files.
Complete in 475ms.
Running formatters.
Complete in 384ms.
Formatted 0 of 3 files.
Format complete in 1934ms.
TestInclude.rsp
src/Analyzers/AnalyzerFinderHelpers.cs
src/Analyzers/AnalyzerReferenceAnalyzerFinder.cs
src/Analyzers/Extensions.cs
@JoeRobich can you test if that works with file is >32kB?
Also that @TestInclude.rsp
is some kind of PowerShell command or feature of dotnet-format?
@martinsuchan It is a feature of the command line parsing library that we use. For instance, In my post above I was running in bash. I have found an issue with large rsp files (https://github.com/dotnet/command-line-api/issues/863). I will put in a PR to update to a build containing the fix.
opened https://github.com/dotnet/format/pull/700 to pull in the fix.
@martinsuchan if you would like to try with the fix merged in you can install a development build with this command - dotnet tool install -g dotnet-format --version 4.1.130802 --add-source https://dotnet.myget.org/F/format/api/v3/index.json
. Using it locally I ran against a 39KB rsp generated by find ./src > TestInclude.rsp
no problem.
@JoeRobich this looks like a good solution for my problem. It might be a good idea to add this way of using --include
and --exclude
into README.md
, I had no idea this syntax exists.
Maybe a little on the extreme end by when use an rsp file that is 134kb I get this error
System.ComponentModel.Win32Exception (206): An error occurred trying to start process 'c:\program files\dotnet\dotnet.exe' with working directory '<my_repo>'. The filename or extension is too long.
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at Microsoft.DotNet.Cli.Utils.ProcessStartInfoExtensions.Execute(ProcessStartInfo startInfo)
at System.CommandLine.Invocation.InvocationPipeline.Invoke(ParseResult parseResult)
at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, TimeSpan startupTime, ITelemetry telemetryClient)
I'm on windows 10 using dotnet 8 sdk.
I've wittled it down to a the breaking limit - 32kb Good, 33kb it fails
Right now it's possible to use the --include argument to include only specific list of files to check. This is a handy feature, but the user might hit the limit of maximum command length 32 767 characters, or 8 191 when executed from cmd.exe. https://support.microsoft.com/en-us/help/830473/command-prompt-cmd-exe-command-line-string-limitation
Feature request: add option to specify path of a file with list of files/folders to include, or similarly to exclude. The argument name could be
--includeList
or--excludeList
.