66using System . Text . RegularExpressions ;
77using System . Threading . Tasks ;
88using UnityEditor ;
9+ using UnityEditor . Experimental . GraphView ;
910using UnityEngine ;
1011using PackageInfo = UnityEditor . PackageManager . PackageInfo ;
1112
1213namespace Abuksigun . MRGitUI
1314{
1415 using static Const ;
1516
17+ public enum ConfigScope { Global , Local , None }
18+
19+ public record ConfigRef ( string key , ConfigScope scope ) ;
1620 public record BlameLine ( string Hash , string Author , DateTime Date , string Text , int Line ) ;
1721 public record Reference ( string Name , string QualifiedName , string Hash ) ;
1822 public record Tag ( string Name , string Hash ) : Reference ( Name , Name , Hash ) ;
@@ -67,6 +71,7 @@ public class Module
6771 Dictionary < int , Task < GitStatus > > diffCache ;
6872 Dictionary < int , Task < string [ ] > > fileLogCache ;
6973 Dictionary < string , Task < BlameLine [ ] > > fileBlameCache ;
74+ Dictionary < ConfigRef , Task < string > > configCache ;
7075
7176 List < IOData > processLog = new ( ) ;
7277 List < IOData > processLogConcurent = new ( ) ;
@@ -166,6 +171,17 @@ public Task<BlameLine[]> BlameFile(string filePath)
166171 fileBlameCache ??= new ( ) ;
167172 return fileBlameCache . TryGetValue ( filePath , out var blame ) ? blame : fileBlameCache [ filePath ] = GetBlame ( filePath ) ;
168173 }
174+ public Task < string > GitConfigValue ( string key , ConfigScope scope )
175+ {
176+ configCache ??= new ( ) ;
177+ var configRef = new ConfigRef ( key , scope ) ;
178+ return configCache . TryGetValue ( configRef , out var blame ) ? blame : configCache [ configRef ] = GetGitConfigValue ( key , scope ) ;
179+ }
180+ async Task < string > GetGitConfigValue ( string key , ConfigScope scope )
181+ {
182+ var result = await RunGit ( $ "config { ScopeToString ( scope ) } --get { key } ") ;
183+ return result . Output . Trim ( ) ;
184+ }
169185 async Task < string > GetRepoPath ( )
170186 {
171187 return ( await RunGit ( "rev-parse --show-toplevel" ) ) . Output . Trim ( ) ;
@@ -405,6 +421,8 @@ public void RefreshFilesStatus()
405421 gitStatus = null ;
406422 fileDiffCache = null ;
407423 diffCache = null ;
424+ configCache = null ;
425+ AssetDatabase . Refresh ( ) ;
408426 }
409427
410428 #region Remotes Managment
@@ -511,5 +529,21 @@ public Task<CommandResult> Stash(string commitMessage, IEnumerable<string> files
511529 return RunGit ( $ "stash push -m { commitMessage . WrapUp ( ) } -- { PackageShortcuts . JoinFileNames ( files ) } ") . AfterCompletion ( RefreshFilesStatus , RefreshReferences ) ;
512530 }
513531 #endregion
532+
533+ #region Config
534+ public Task < CommandResult > UnsetConfig ( string key , ConfigScope scope )
535+ {
536+ return RunGit ( $ "config --unset { ScopeToString ( scope ) } { key } ") . AfterCompletion ( RefreshFilesStatus , RefreshReferences ) ;
537+ }
538+ public Task < CommandResult > SetConfig ( string key , ConfigScope scope , string newValue )
539+ {
540+ return RunGit ( $ "config { ScopeToString ( scope ) } { key } \" { newValue } \" ") . AfterCompletion ( RefreshFilesStatus , RefreshReferences ) ;
541+ }
542+ #endregion
543+
544+ static string ScopeToString ( ConfigScope scope )
545+ {
546+ return scope != ConfigScope . None ? "--" + scope . ToString ( ) . ToLower ( ) : null ;
547+ }
514548 }
515549}
0 commit comments