Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8f249d2567 |
@@ -1,15 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\OmegaLeo.HelperLib.Git\OmegaLeo.HelperLib.Git.csproj" />
|
|
||||||
<ProjectReference Include="..\OmegaLeo.HelperLib\OmegaLeo.HelperLib.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
// See https://aka.ms/new-console-template for more information
|
|
||||||
|
|
||||||
// /media/omegaleo/Development/Library Dev/HelperLib
|
|
||||||
|
|
||||||
using GameDevLibrary.Extensions;
|
|
||||||
using LibGit2Sharp;
|
|
||||||
using OmegaLeo.HelperLib.Git;
|
|
||||||
using OmegaLeo.HelperLib.Git.Models;
|
|
||||||
|
|
||||||
Console.WriteLine("Insert repo path to check changes:");
|
|
||||||
var repo = Console.ReadLine();
|
|
||||||
|
|
||||||
if (repo.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
repo = "/media/omegaleo/Development/Library Dev/HelperLib";
|
|
||||||
}
|
|
||||||
|
|
||||||
var git = new GitClient(repo);
|
|
||||||
|
|
||||||
var changes = git.GetChanges();
|
|
||||||
|
|
||||||
if (changes.FolderName.IsNotNullOrEmpty())
|
|
||||||
{
|
|
||||||
RecursiveOutput(new List<ChangeFolder>() { changes });
|
|
||||||
|
|
||||||
var option = 99;
|
|
||||||
|
|
||||||
while (option != 0)
|
|
||||||
{
|
|
||||||
ShowOptions();
|
|
||||||
if (option != 99)
|
|
||||||
{
|
|
||||||
switch (option)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
Console.WriteLine("Write the commit message");
|
|
||||||
var msg = Console.ReadLine();
|
|
||||||
|
|
||||||
while (msg.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
Console.WriteLine("Empty message detected, please write a commit message...");
|
|
||||||
msg = Console.ReadLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
var signature = new Signature("Nuno 'Omega Leo' Diogo", "nunodiogo@omegaleo.pt", DateTimeOffset.Now);
|
|
||||||
git.Commit(msg, signature);
|
|
||||||
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
git.Push();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Console.WriteLine("Invalid Option!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int.TryParse(Console.ReadLine(), out option);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("No changes found in specified repository");
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.ReadLine();
|
|
||||||
|
|
||||||
|
|
||||||
void RecursiveOutput(List<ChangeFolder> folders, int depth = 0)
|
|
||||||
{
|
|
||||||
foreach (var folder in folders)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"{new string('\t', depth)}>{folder.FolderName}");
|
|
||||||
if (folder.SubFolders.Any())
|
|
||||||
{
|
|
||||||
RecursiveOutput(folder.SubFolders, depth + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var change in folder.ChangesInFolder)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"{new string('\t', depth + 1)}>{Path.GetFileName(change.Path)} ({change.Status})");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShowOptions()
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
Console.WriteLine(new string('=', 20));
|
|
||||||
Console.WriteLine("What do you want to do in this repository?");
|
|
||||||
Console.WriteLine("1. Commit all changes");
|
|
||||||
Console.WriteLine("2. Push");
|
|
||||||
}
|
|
||||||
@@ -1,130 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using GameDevLibrary.Extensions;
|
|
||||||
using LibGit2Sharp;
|
|
||||||
using OmegaLeo.HelperLib.Git.Models;
|
|
||||||
|
|
||||||
namespace OmegaLeo.HelperLib.Git
|
|
||||||
{
|
|
||||||
public class GitClient
|
|
||||||
{
|
|
||||||
private Repository _repo;
|
|
||||||
|
|
||||||
public GitClient(string path)
|
|
||||||
{
|
|
||||||
if (path.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
path = AppDomain.CurrentDomain.BaseDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
_repo = new Repository(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CheckoutBranch(string branchName)
|
|
||||||
{
|
|
||||||
var branch = _repo.Branches[branchName];
|
|
||||||
|
|
||||||
if (branch == null)
|
|
||||||
{
|
|
||||||
branch = _repo.CreateBranch(branchName);
|
|
||||||
}
|
|
||||||
|
|
||||||
Commands.Checkout(_repo, branch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool HasChanges() => _repo.Diff.Compare<TreeChanges>().Count > 0;
|
|
||||||
|
|
||||||
public ChangeFolder GetChanges()
|
|
||||||
{
|
|
||||||
var folder = new ChangeFolder();
|
|
||||||
|
|
||||||
if (HasChanges())
|
|
||||||
{
|
|
||||||
var changes = _repo.Diff.Compare<TreeChanges>();
|
|
||||||
|
|
||||||
var allChanges = new List<TreeEntryChanges>();
|
|
||||||
allChanges.AddRange(changes.Added);
|
|
||||||
allChanges.AddRange(changes.Modified);
|
|
||||||
allChanges.AddRange(changes.Deleted);
|
|
||||||
|
|
||||||
var uniqueFolderPaths = allChanges.Select(x => Path.GetDirectoryName(x.Path)).Distinct();
|
|
||||||
|
|
||||||
foreach (var path in uniqueFolderPaths)
|
|
||||||
{
|
|
||||||
if (path.IsNullOrEmpty()) continue;
|
|
||||||
|
|
||||||
if (path.Contains(Path.DirectorySeparatorChar))
|
|
||||||
{
|
|
||||||
var paths = path.Split(Path.DirectorySeparatorChar);
|
|
||||||
|
|
||||||
for (var i = 0; i < paths.Length; i++)
|
|
||||||
{
|
|
||||||
var p = paths[i];
|
|
||||||
|
|
||||||
if (folder.FolderName.Equals(p))
|
|
||||||
{
|
|
||||||
if (folder.ChangesInFolder.Any()) continue;
|
|
||||||
|
|
||||||
folder.ChangesInFolder =
|
|
||||||
allChanges.Where(x => Path.GetDirectoryName(x.Path)!.Equals(p, StringComparison.OrdinalIgnoreCase));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var pathList = paths[0..(i+1)].ToList();
|
|
||||||
var subFolder = folder.RecursiveGet(pathList);
|
|
||||||
var fullPath = string.Join(Path.DirectorySeparatorChar, pathList);
|
|
||||||
|
|
||||||
if (!subFolder.ChangesInFolder.Any())
|
|
||||||
{
|
|
||||||
subFolder.ChangesInFolder = allChanges.Where(x =>
|
|
||||||
Path.GetDirectoryName(x.Path)!.Equals(fullPath, StringComparison.OrdinalIgnoreCase));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
folder.FolderName = path;
|
|
||||||
folder.ChangesInFolder =
|
|
||||||
allChanges.Where(x => Path.GetDirectoryName(x.Path)!.Equals(path, StringComparison.OrdinalIgnoreCase));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return folder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Commit(string message, Signature author)
|
|
||||||
{
|
|
||||||
if (HasChanges())
|
|
||||||
{
|
|
||||||
var changes = _repo.Diff.Compare<TreeChanges>();
|
|
||||||
var allChanges = new List<TreeEntryChanges>();
|
|
||||||
allChanges.AddRange(changes.Added);
|
|
||||||
allChanges.AddRange(changes.Modified);
|
|
||||||
allChanges.AddRange(changes.Deleted);
|
|
||||||
|
|
||||||
var filePaths = allChanges.Select(x => x.Path).Where(x => x.IsNotNullOrEmpty());
|
|
||||||
|
|
||||||
Commands.Stage(_repo, filePaths);
|
|
||||||
}
|
|
||||||
|
|
||||||
_repo.Commit(message, author, author);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Push()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
var remote = _repo.Network.Remotes["origin"];
|
|
||||||
var options = new PushOptions();
|
|
||||||
var pushRefSpec = @"refs/heads/master";
|
|
||||||
_repo.Network.Push(remote, new string[] {pushRefSpec}, options);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
Console.WriteLine("Exception:RepoActions:PushChanges " + e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using LibGit2Sharp;
|
|
||||||
|
|
||||||
namespace OmegaLeo.HelperLib.Git.Models
|
|
||||||
{
|
|
||||||
public class ChangeFolder
|
|
||||||
{
|
|
||||||
public string FolderName { get; set; }
|
|
||||||
public List<ChangeFolder> SubFolders { get; set; }
|
|
||||||
public IEnumerable<TreeEntryChanges> ChangesInFolder { get; set; }
|
|
||||||
|
|
||||||
public ChangeFolder()
|
|
||||||
{
|
|
||||||
FolderName = "";
|
|
||||||
SubFolders = new List<ChangeFolder>();
|
|
||||||
ChangesInFolder = new List<TreeEntryChanges>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChangeFolder RecursiveGet(List<string> paths)
|
|
||||||
{
|
|
||||||
if (!paths.Any()) return null;
|
|
||||||
|
|
||||||
var tempPaths = paths;
|
|
||||||
var pathToCheck = tempPaths.FirstOrDefault();
|
|
||||||
|
|
||||||
ChangeFolder folder = new ChangeFolder();
|
|
||||||
|
|
||||||
if (FolderName.Equals(pathToCheck, StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
folder = this;
|
|
||||||
}
|
|
||||||
else if (SubFolders.Any(x => x.FolderName.Equals(pathToCheck)))
|
|
||||||
{
|
|
||||||
folder = SubFolders.FirstOrDefault(x => x.FolderName.Equals(pathToCheck))!;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
folder.FolderName = pathToCheck;
|
|
||||||
SubFolders.Add(folder);
|
|
||||||
}
|
|
||||||
|
|
||||||
tempPaths.RemoveAt(0);
|
|
||||||
|
|
||||||
if (tempPaths.Any())
|
|
||||||
{
|
|
||||||
return folder.RecursiveGet(tempPaths);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return folder;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>netstandard2.1</TargetFramework>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<RootNamespace>GameDevLibrary.Git</RootNamespace>
|
|
||||||
<Version>0.0.2</Version>
|
|
||||||
<Title>Omega Leo's Helper Library - LibGit2Sharp Implementation</Title>
|
|
||||||
<Authors>Nuno "Omega Leo" Diogo</Authors>
|
|
||||||
<PackageProjectUrl>https://github.com/omegaleo/HelperLib</PackageProjectUrl>
|
|
||||||
<RepositoryUrl>https://github.com/omegaleo/HelperLib</RepositoryUrl>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="LibGit2Sharp" Version="0.30.0"/>
|
|
||||||
<PackageReference Include="NetFlow.DocumentationHelper.Library" Version="1.1.2"/>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\OmegaLeo.HelperLib\OmegaLeo.HelperLib.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -2,10 +2,6 @@
|
|||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmegaLeo.HelperLib", "OmegaLeo.HelperLib\OmegaLeo.HelperLib.csproj", "{A7256931-5D66-46FA-BA50-22B2FA4CD9E9}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmegaLeo.HelperLib", "OmegaLeo.HelperLib\OmegaLeo.HelperLib.csproj", "{A7256931-5D66-46FA-BA50-22B2FA4CD9E9}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmegaLeo.HelperLib.Git", "OmegaLeo.HelperLib.Git\OmegaLeo.HelperLib.Git.csproj", "{A9579FFB-9A05-4EBF-B298-513C48FB0F91}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OmegaLeo.HelperLib.ConsoleApp", "OmegaLeo.HelperLib.ConsoleApp\OmegaLeo.HelperLib.ConsoleApp.csproj", "{3B77B177-FD47-470A-B0EF-01EF8B30CE09}"
|
|
||||||
EndProject
|
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -16,13 +12,5 @@ Global
|
|||||||
{A7256931-5D66-46FA-BA50-22B2FA4CD9E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{A7256931-5D66-46FA-BA50-22B2FA4CD9E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{A7256931-5D66-46FA-BA50-22B2FA4CD9E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{A7256931-5D66-46FA-BA50-22B2FA4CD9E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{A7256931-5D66-46FA-BA50-22B2FA4CD9E9}.Release|Any CPU.Build.0 = Release|Any CPU
|
{A7256931-5D66-46FA-BA50-22B2FA4CD9E9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{A9579FFB-9A05-4EBF-B298-513C48FB0F91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{A9579FFB-9A05-4EBF-B298-513C48FB0F91}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{A9579FFB-9A05-4EBF-B298-513C48FB0F91}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{A9579FFB-9A05-4EBF-B298-513C48FB0F91}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{3B77B177-FD47-470A-B0EF-01EF8B30CE09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{3B77B177-FD47-470A-B0EF-01EF8B30CE09}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{3B77B177-FD47-470A-B0EF-01EF8B30CE09}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{3B77B177-FD47-470A-B0EF-01EF8B30CE09}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelper_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003Fhome_003Fomegaleo_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fc61cc76f205b4535a5b4f40700c07900b2d200_003Fe5_003F6b3ec67e_003FThrowHelper_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATreeChanges_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003Fhome_003Fomegaleo_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F7478b0ce6362feb345e793626f5c504bd9d7ffeb748226521658c85fc4e29_003FTreeChanges_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATreeEntryChanges_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003Fhome_003Fomegaleo_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F2b7912eaeadb1d9a91a3f891a244b5cd4a856d9dde42694e941ee6a2994_003FTreeEntryChanges_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
|
||||||
@@ -98,7 +98,7 @@ namespace GameDevLibrary.Extensions
|
|||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public static IEnumerable<TSource> DistinctBy<TSource, TKey>
|
public static IEnumerable<TSource> DistinctBy<TSource, TKey>
|
||||||
(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
|
(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
|
||||||
{
|
{
|
||||||
HashSet<TKey> seenKeys = new HashSet<TKey>();
|
HashSet<TKey> seenKeys = new HashSet<TKey>();
|
||||||
@@ -109,7 +109,7 @@ namespace GameDevLibrary.Extensions
|
|||||||
yield return element;
|
yield return element;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
|
||||||
// Idea obtained from TaroDev's video on things to do in Unity - https://youtu.be/Ic5ux-tpkCE?t=302
|
// Idea obtained from TaroDev's video on things to do in Unity - https://youtu.be/Ic5ux-tpkCE?t=302
|
||||||
|
|||||||
Reference in New Issue
Block a user