public static void ConfigCounts() { Console.WriteLine($"currentDir: {Environment.CurrentDirectory}"); using (var tempDir = new TempGitDir()) { var local = GitConfig.Load(); var global = local.Parent; var system = global.Parent; var systemKeys = system.ToArray(); var globalKeys = global.ToArray(); var localKeys = local.ToArray(); Assert.AreEqual(local.Count, local.Count()); Assert.AreEqual(global.Count, global.Count()); Assert.AreEqual(system.Count, system.Count()); } }
public static LfxConfig Load(string path = null) { if (path != null) { path += LfxConfigFile.FileName; if (File.Exists(path)) { return(Load(GitConfig.Load(path))); } path = path.GetDir(); } var gitConfig = GitConfig.Load(path, LfxConfigFile.FileName); if (gitConfig == null) { return(null); } return(Load(gitConfig)); }
public static LfxBlobCache Create(string workingDir = null) { if (workingDir == null) { workingDir = Environment.CurrentDirectory; } workingDir = workingDir.ToDir(); var gitLoader = GitConfig.Load(workingDir); // lfxDir -> /.git/lfx/ var lfxDir = gitLoader.GitDirectory + LfxDirName.ToDir(); // objectsDir -> /.git/lfx/objects/ var objectsDir = lfxDir + ObjectsDirName.ToDir(); var cache = Create( objectsDir, // L1 cache DefaultUserCacheDir // L2 cache ); return(cache); }
public static void ManualTest() { Console.WriteLine($"currentDir: {Environment.CurrentDirectory}"); using (var tempDir = new TempDir()) { var tempDirString = (string)tempDir; Console.WriteLine($"tempDir: {tempDir}"); using (var env = new TempCurDir(ToolsDirName)) { // copy git-lfx.exe and libs to tools dir typeof(ImmutableDictionary).Assembly.Location.CopyToDir(); typeof(GitCmd).Assembly.Location.CopyToDir(); typeof(LfxCmd).Assembly.Location.CopyToDir(); typeof(Program).Assembly.Location.CopyToDir(); // add tools dir to path Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";" + env ); } using (var env = new TempCurDir(RemoteDirName)) { Git($"init --bare"); } using (var env = new TempCurDir(SourceDirName)) { Git($"init"); Git($"remote add origin ..\\{RemoteDirName}"); Git($"config --add filter.lfx.clean \"git-lfx clean %f\""); Git($"config --add filter.lfx.smudge \"git-lfx smudge --\""); Git($"config --get-regex .*lfx.*"); PackagesConfig.Save("packages.config"); using (var packages = new TempCurDir("packages")) { File.WriteAllText(GitAttributes, NugetGitAttributes); File.WriteAllText(GitIgnore, NugetGitIgnore); var gitConfig = GitConfig.Load(); Assert.AreEqual(env.ToString(), gitConfig.EnlistmentDirectory); Git($"config -f {LfxConfig} --add {LfxConfigFile.TypeId} {NugetType}"); Git($"config -f {LfxConfig} --add {LfxConfigFile.UrlId} {NugetUrl}"); Git($"config -f {LfxConfig} --add {LfxConfigFile.PatternId} {NugetRegex}"); Git($"config -f {LfxConfig} --add {LfxConfigFile.HintId} {NugetHint}"); Console.WriteLine($"{LfxConfig}: {Path.GetFullPath(LfxConfig)}:"); Console.WriteLine(File.ReadAllText(LfxConfig)); } Nuget($"restore -packagesDirectory packages"); Cmd($"where.exe", "git-lfx.exe"); Git($"add ."); Git($"commit -m \"Initial Commit\""); Git($"push -u origin master"); } Git($"clone remote target"); Console.WriteLine($"CurDir: {Environment.CurrentDirectory}"); } }
public static void Test() { Console.WriteLine($"currentDir: {Environment.CurrentDirectory}"); using (var tempDir = new TempDir()) { var tempDirString = (string)tempDir; Console.WriteLine($"tempDir: {tempDir}"); Git($"init"); var local = GitConfig.Load(); var global = local.Parent; var system = global.Parent; Assert.IsNull(system.Parent); Assert.IsTrue(!system.Except(local).Any()); Assert.IsTrue(!system.Except(global).Any()); Assert.IsTrue(!global.Except(local).Any()); Assert.AreEqual(local.Count, local.Count()); Assert.IsTrue(system.Keys().All(o => local.Contains(o))); Assert.IsTrue(system.Keys().All(o => global.Contains(o))); Assert.IsTrue(global.Keys().All(o => local.Contains(o))); Assert.IsTrue(!system.Keys().Except(local.Keys()).Any()); Assert.IsTrue(!global.Keys().Except(local.Keys()).Any()); Assert.AreEqual((string)tempDir, local.EnlistmentDirectory); Assert.AreEqual(null, global.EnlistmentDirectory); Assert.AreEqual(null, system.EnlistmentDirectory); var localFile = local.ConfigFile; Assert.AreEqual((string)tempDir, localFile.WorkingDir); Assert.AreEqual(tempDir + @".git\config", localFile.Path); var globalFile = global.ConfigFile; var systemFile = system.ConfigFile; var count = localFile.Count + globalFile.Count + systemFile.Count; Assert.AreEqual( local.Count, localFile.Keys().Union( globalFile.Keys().Union( systemFile.Keys())).Count() ); var myKey = "myKey.mySubKey"; var myValue = "myValue"; Git($"config --add {myKey} {myValue}"); var localFile0 = localFile.Reload(); var local0 = local.Reload(); Assert.AreEqual(localFile.Count + 1, local0.ConfigFile.Count); string result; Assert.IsFalse(local.TryGetValue(myKey, out result)); Assert.IsFalse(localFile.TryGetValue(myKey, out result)); Assert.IsTrue(local0.TryGetValue(myKey, out result)); Assert.AreEqual(myValue, result); Assert.IsTrue(local0.ConfigFile.TryGetValue(myKey, out result)); Assert.AreEqual(myValue, result); Assert.AreEqual(myValue, (string)local0[myKey]); Console.WriteLine("systemFile:"); foreach (var keyValue in systemFile) { Console.WriteLine(" " + keyValue.ToString()); } Console.WriteLine("globalFile:"); foreach (var keyValue in globalFile) { Console.WriteLine(" " + keyValue.ToString()); } Console.WriteLine("localFile:"); foreach (var keyValue in localFile) { Console.WriteLine(" " + keyValue.ToString()); } Console.WriteLine("config:"); foreach (var keyValue in local) { Console.WriteLine(" " + keyValue.ToString()); } } }