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