Better git remote management
This commit is contained in:
parent
35ea9825e8
commit
c0faca2336
@ -8,20 +8,23 @@ internal static partial class Helper20240711
|
||||
|
||||
internal static void GitRemoteRemove(ILogger<Worker> logger, List<string> args)
|
||||
{
|
||||
string line;
|
||||
string[] lines;
|
||||
bool branchCheck;
|
||||
bool remoteCheck;
|
||||
string? directory;
|
||||
string parentDirectoryName;
|
||||
string? parentDirectory;
|
||||
string branchName = args[6];
|
||||
string parentDirectoryName;
|
||||
string branchName = args[8];
|
||||
string searchPattern = args[2];
|
||||
string remoteToAddUrl = args[5];
|
||||
string remoteToAddUrl = args[6];
|
||||
string remoteToRemove = args[3];
|
||||
string remoteToAddName = args[4];
|
||||
string remoteToAddName = args[5];
|
||||
ReadOnlyCollection<string> messages;
|
||||
string remoteToRemoveFilter = args[4];
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
string lastRemoteSegment = remoteToRemove.Split('/')[^1];
|
||||
string extension = args[7].Length > 2 ? args[6] : string.Empty;
|
||||
string[] files = Directory.EnumerateFiles(sourceDirectory, searchPattern, new EnumerationOptions() { IgnoreInaccessible = true, RecurseSubdirectories = true, AttributesToSkip = FileAttributes.None }).ToArray();
|
||||
logger.LogInformation("Found {files} file(s)", files.Length);
|
||||
foreach (string file in files)
|
||||
@ -29,15 +32,19 @@ internal static partial class Helper20240711
|
||||
branchCheck = false;
|
||||
remoteCheck = false;
|
||||
lines = File.ReadAllLines(file);
|
||||
foreach (string line in lines)
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
line = lines[i];
|
||||
if (!line.Contains(remoteToRemove))
|
||||
continue;
|
||||
if (!lines[i - 1].Contains(remoteToRemoveFilter))
|
||||
continue;
|
||||
remoteCheck = true;
|
||||
break;
|
||||
}
|
||||
foreach (string line in lines)
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
line = lines[i];
|
||||
if (!line.Contains(branchName))
|
||||
continue;
|
||||
branchCheck = true;
|
||||
@ -52,17 +59,18 @@ internal static partial class Helper20240711
|
||||
if (parentDirectory is null)
|
||||
continue;
|
||||
parentDirectoryName = Path.GetFileName(parentDirectory).ToLower();
|
||||
messages = Helpers.HelperGit.RemoteRemove(directory, lastRemoteSegment, CancellationToken.None);
|
||||
messages = Helpers.HelperGit.RemoteRemove(parentDirectory, lastRemoteSegment, CancellationToken.None);
|
||||
foreach (string message in messages)
|
||||
logger.LogInformation("{function} => {parentDirectoryName}: [{message}]", nameof(Helpers.HelperGit.RemoteRemove), parentDirectoryName, message);
|
||||
messages = Helpers.HelperGit.RemoteAdd(directory, remoteToAddName, $"{remoteToAddUrl}{parentDirectoryName}.git", CancellationToken.None);
|
||||
messages = Helpers.HelperGit.RemoteAdd(parentDirectory, remoteToAddName, $"{remoteToAddUrl}{parentDirectoryName}{extension}", CancellationToken.None);
|
||||
foreach (string message in messages)
|
||||
logger.LogInformation("{function} => {parentDirectoryName}: [{message}]", nameof(Helpers.HelperGit.RemoteAdd), parentDirectoryName, message);
|
||||
if (!branchCheck)
|
||||
continue;
|
||||
try
|
||||
{ messages = Helpers.HelperGit.PushBranch(directory, remoteToAddName, branchName, CancellationToken.None); }
|
||||
catch (Exception) { }
|
||||
{ messages = Helpers.HelperGit.PushBranch(parentDirectory, remoteToAddName, branchName, CancellationToken.None); }
|
||||
catch (Exception)
|
||||
{ messages = new([]); }
|
||||
foreach (string message in messages)
|
||||
logger.LogInformation("{function} => {parentDirectoryName}: [{message}]", nameof(Helpers.HelperGit.PushBranch), parentDirectoryName, message);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user