Skip to content

Commit 15d706f

Browse files
committed
Add the darc vmr diff --name-only option
dotnet/source-build#5201
1 parent cc35b0b commit 15d706f

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

src/Microsoft.DotNet.Darc/Darc/Operations/VirtualMonoRepo/VmrDiffOperation.cs

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,21 +285,57 @@ await processManager.ExecuteGit(repo1, [
285285
includeAdditionalMappings: false,
286286
CancellationToken.None);
287287

288-
// If tmpDirectory is not null, it means the output path was not provided, so we just want to
289-
// print out the whole diff
290-
if (!string.IsNullOrEmpty(tmpDirectory))
288+
try
291289
{
292-
foreach (var patch in patches)
290+
if (options.NameOnly)
291+
{
292+
var files = new List<UnixPath>();
293+
294+
// For name-only mode, we'll print the filenames directly from the git patch summary lines
295+
foreach (var patch in patches)
296+
{
297+
files.AddRange(await patchHandler.GetPatchedFiles(patch.Path, CancellationToken.None));
298+
}
299+
300+
var list = files
301+
.Select(f => f.Path)
302+
.OrderBy(f => f);
303+
304+
// If the output path was provided, the list will be stored there
305+
// Otherwise we want to print it
306+
if (string.IsNullOrEmpty(options.OutputPath))
307+
{
308+
foreach (var file in list)
309+
{
310+
Console.WriteLine(file);
311+
}
312+
}
313+
else
314+
{
315+
await File.WriteAllLinesAsync(outputPath, list);
316+
}
317+
}
318+
else
293319
{
294-
using FileStream fs = new(patch.Path, FileMode.Open, FileAccess.Read);
295-
using StreamReader sr = new(fs);
296-
string? line;
297-
while ((line = await sr.ReadLineAsync()) != null)
320+
// For regular diff mode, we print the full diff content
321+
foreach (var patch in patches)
298322
{
299-
Console.WriteLine(line);
323+
using FileStream fs = new(patch.Path, FileMode.Open, FileAccess.Read);
324+
using StreamReader sr = new(fs);
325+
string? line;
326+
while ((line = await sr.ReadLineAsync()) != null)
327+
{
328+
Console.WriteLine(line);
329+
}
300330
}
301331
}
302-
fileSystem.DeleteDirectory(tmpDirectory, true);
332+
}
333+
finally
334+
{
335+
if (!string.IsNullOrEmpty(tmpDirectory))
336+
{
337+
fileSystem.DeleteDirectory(tmpDirectory, true);
338+
}
303339
}
304340
}
305341

src/Microsoft.DotNet.Darc/Darc/Options/VirtualMonoRepo/VmrDiffOptions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.DotNet.Darc.Operations.VirtualMonoRepo;
66

77
namespace Microsoft.DotNet.Darc.Options.VirtualMonoRepo;
8+
89
[Verb("diff", HelpText = "Diffs the VMR and the product repositories. Outputs the diff to stdout, "
910
+ "or saves it to a patch file (or multiple if patch > 1 GB), if --output-path is provided")]
1011
internal class VmrDiffOptions : VmrCommandLineOptions<VmrDiffOperation>
@@ -17,4 +18,7 @@ internal class VmrDiffOptions : VmrCommandLineOptions<VmrDiffOperation>
1718
"where remote can be a local path or remote URI. Alternatively, only one target can be provided in " +
1819
"which case current directory will be used as the source for the diff")]
1920
public string Repositories { get; set; }
21+
22+
[Option("name-only", Required = false, HelpText = "Only list differing files without the diffs")]
23+
public bool NameOnly { get; set; }
2024
}

0 commit comments

Comments
 (0)