public void Config() { var args = Parse( maxArgs: 0, switchInfo: GitCmdSwitchInfo.Create( LfxCmdSwitches.List, LfxCmdSwitches.L, LfxCmdSwitches.Unset, LfxCmdSwitches.Set ) ); if (args.IsSet(LfxCmdSwitches.List, LfxCmdSwitches.L)) { Git($"config --show-origin --get-regex filter.lfx.*"); } else if (args.IsSet(LfxCmdSwitches.Unset)) { Git($"config --unset-all filter.lfx.clean"); Git($"config --unset-all filter.lfx.smudge"); } else if (args.IsSet(LfxCmdSwitches.Set)) { Git($"config --replace-all filter.lfx.clean \"git-lfx clean %f\""); Git($"config --replace-all filter.lfx.smudge \"git-lfx smudge --\""); } else { throw new GitCmdException("Config argument check failure."); } }
public void Reset() { var args = Parse( minArgs: 0, maxArgs: 1, switchInfo: GitCmdSwitchInfo.Create( LfxCmdSwitches.List, LfxCmdSwitches.L, LfxCmdSwitches.Cached, LfxCmdSwitches.C, LfxCmdSwitches.Others, LfxCmdSwitches.O, LfxCmdSwitches.Quite, LfxCmdSwitches.Q, LfxCmdSwitches.Force, LfxCmdSwitches.F ) ); var lfxFiles = GetFiles(args, content: true); var listOnly = args.IsSet(LfxCmdSwitches.L, LfxCmdSwitches.List); if (listOnly) { foreach (var file in lfxFiles) { Log($"{file}"); } return; } var force = args.IsSet(LfxCmdSwitches.F, LfxCmdSwitches.Force); var cache = LfxBlobCache.Create(); Batch(args, lfxFiles, file => { var path = file.Path; if (force) { var mask = ~(FileAttributes.Hidden | FileAttributes.ReadOnly | FileAttributes.System); File.SetAttributes( path: path, fileAttributes: File.GetAttributes(path) & mask ); } if (!LfxPointer.CanLoad(path)) { var blob = cache.Save(path); var pointer = LfxPointer.Create(path, blob.Hash); pointer.Save(path); } }); }
private GitCmdArgs Parse( int minArgs = 0, int maxArgs = int.MaxValue, IEnumerable <GitCmdSwitchInfo> switchInfo = null) { if (switchInfo == null) { switchInfo = GitCmdSwitchInfo.Create(); } return(GitCmdArgs.Parse(m_commandLine, minArgs, maxArgs, switchInfo)); }
public static void KnownSwitchEnum() { var args = GitCmdArgs.Parse( $"{ExeName} -{ShortSwitch} --{LongSwitch}", switchInfo: GitCmdSwitchInfo.Create( KnownSwitches.MyGitSwitch, KnownSwitches.M ) ); Assert.IsTrue(args.IsSet(KnownSwitches.MyGitSwitch)); Assert.IsTrue(args.IsSet(KnownSwitches.M)); }
public static void UnknownSwitchName() { var switches = GitCmdSwitchInfo.Create( ShortSwitch, LongSwitch ); var longSwitchCmd = $"{ExeName} --{OtherLongSwitch}"; GitCmdArgs.Parse(longSwitchCmd); Throws(() => GitCmdArgs.Parse(longSwitchCmd, switchInfo: switches)); var shortSwitchCmd = $"{ExeName} -{OtherShortSwitch}"; GitCmdArgs.Parse(shortSwitchCmd); Throws(() => GitCmdArgs.Parse(shortSwitchCmd, switchInfo: switches)); }
public void Checkout() { var args = Parse( minArgs: 0, maxArgs: 1, switchInfo: GitCmdSwitchInfo.Create( LfxCmdSwitches.List, LfxCmdSwitches.L, LfxCmdSwitches.Cached, LfxCmdSwitches.C, LfxCmdSwitches.Others, LfxCmdSwitches.O, LfxCmdSwitches.Quite, LfxCmdSwitches.Q ) ); var lfxFiles = GetFiles(args, pointer: true); var listOnly = args.IsSet(LfxCmdSwitches.L, LfxCmdSwitches.List); if (listOnly) { foreach (var file in lfxFiles) { Log($"{file}"); } return; } var cache = LfxBlobCache.Create(); Batch(args, lfxFiles, async file => { LfxPointer pointer; if (!LfxPointer.TryLoad(file.Path, out pointer)) { return; } var blob = await cache.LoadAsync(pointer); blob.Save(file.Path); }); }
public void Files() { var args = Parse( minArgs: 0, maxArgs: 1, switchInfo: GitCmdSwitchInfo.Create( LfxCmdSwitches.Cached, LfxCmdSwitches.C, LfxCmdSwitches.Others, LfxCmdSwitches.O, LfxCmdSwitches.Content, LfxCmdSwitches.Pointer ) ); foreach (var file in GetFiles(args)) { Log($"{file}"); } }
public void Init() { var nugetUrl = "https://dist.nuget.org/win-x86-commandline/v3.4.4/NuGet.exe"; var nugetHash = "c12d583dd1b5447ac905a334262e02718f641fca3877d0b6117fe44674072a27"; var nugetCount = 3957976L; var nugetPkgUrl = "http://nuget.org/api/v2/package/${id}/${ver}"; var nugetPkgPattern = "^((?<id>.*?)[.])(?=\\d)(?<ver>[^/]*)/(?<path>.*)$"; var nugetPkgHint = "${path}"; var args = Parse( maxArgs: 0, switchInfo: GitCmdSwitchInfo.Create( LfxCmdSwitches.Sample ) ); Git("init"); Lfx("config --set"); if (!args.IsSet(LfxCmdSwitches.Sample)) { return; } File.WriteAllText(".gitattributes", $"* text=auto"); using (var dls = new TempCurDir("dls")) { File.WriteAllLines(".gitattributes", new[] { $"* filter=lfx diff=lfx merge=lfx -text", $".gitattributes filter= diff= merge= text=auto", $".gitignore filter= diff= merge= text=auto", $"packages.config filter= diff= merge= text=auto", $"*.lfxconfig filter= diff= merge= text eol=lf" }); using (var packages = new TempCurDir("tools")) { Git($"config -f nuget.exe.lfxconfig --add lfx.type curl"); Git($"config -f nuget.exe.lfxconfig --add lfx.url {nugetUrl}"); File.WriteAllText("NuGet.exe", LfxPointer.Create( hash: LfxHash.Parse(nugetHash), count: nugetCount ).AddUrl(nugetUrl.ToUrl()).ToString()); } using (var packages = new TempCurDir("packages")) { File.WriteAllText(".gitignore", $"*.nupkg"); Git($"config -f .lfxconfig --add lfx.type archive"); Git($"config -f .lfxconfig --add lfx.url {nugetPkgUrl}"); Git($"config -f .lfxconfig --add lfx.pattern {nugetPkgPattern}"); Git($"config -f .lfxconfig --add lfx.hint {nugetPkgHint}"); new XElement("packages", new XElement("package", new XAttribute("id", "NUnit"), new XAttribute("version", "2.6.4") ) ).Save("packages.config"); } } }