file-folder-helper/Day/2024-Q2/Helper-2024-04-29.cs
Mike Phares 4e3f06bb44 Minor changes
Empty file ISO
Add date back for just .kanbn
Removed HardcodedFileSearchAndSort
Sync with 01-23
JsonToTsv
System.Text.Json
White-List
Ready to move to Move Helper
Remove Whitelist
Force Start At
Check for .git directory before ls
Optional
Allow root for unc path
nuget bump
PreVerify
EnforceCodeStyleInBuild
dotnet_analyzer_diagnostic
HelperGit
searchDelegate
Host File
AlertIfNewDeviceIsConnected
AOT
SetFrontMatterAndH1
Match Error
Unknown with better logging
Undo 04-05
WriteAppendToHostConfFile
MonA
IsKanbanIndex
Dotnet Format Pre-commit
NPM
CreateWindowsShortcut
Working directory
Split description
Copy tests
Ready to test
Delete after a couple of days
GitConfigCleanUp
knb Files
2024-05-01 09:05:08 -07:00

56 lines
2.1 KiB
C#

using Microsoft.Extensions.Logging;
using System.Diagnostics;
namespace File_Folder_Helper.Day;
internal static partial class Helper20240429
{
internal static void GitConfigCleanUp(ILogger<Worker> logger, List<string> args)
{
string[] files;
Process? process;
string? directory;
string standardError;
string ignoreError = args[5];
string searchPattern = args[3];
ProcessStartInfo processStartInfo;
string root = Path.GetFullPath(args[0]);
string[] removeRemotes = args[4].Split(',');
string systemVolumeInformation = Path.Combine(root, args[2]);
string[] subDirectories = Directory.GetDirectories(root, "*", SearchOption.TopDirectoryOnly);
foreach (string subDirectory in subDirectories)
{
if (subDirectory == systemVolumeInformation)
continue;
files = Directory.GetFiles(subDirectory, searchPattern, SearchOption.AllDirectories);
foreach (string file in files)
{
directory = Path.GetDirectoryName(file);
if (directory is null)
continue;
foreach (string removeRemote in removeRemotes)
{
processStartInfo = new()
{
FileName = "git",
WorkingDirectory = directory,
Arguments = $"remote rm {removeRemote}",
RedirectStandardError = true
};
process = Process.Start(processStartInfo);
if (process is null)
continue;
#pragma warning disable IDE0058
process.WaitForExit(7000);
#pragma warning restore IDE0058
standardError = process.StandardError.ReadToEnd();
if (!standardError.Contains(ignoreError))
logger.LogInformation(standardError);
logger.LogInformation("for <{directoryName}> remote rm {removeRemote}", directory, removeRemote);
}
}
}
}
}