public void Setup() { _localAppDataFolder = $"{_localDataFolder}DWGitsh"; _fileManager = Substitute.For <IFile>(); _diskManager = Substitute.For <IStaticAbstraction>(); _diskManager.File = _fileManager; _diskManager.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData).Returns(_localDataFolder); _diskManager.Path.Combine(_localDataFolder, "DWGitsh").Returns(_localAppDataFolder); _diskManager.Directory.Exists(_localAppDataFolder).Returns(true); _diskManager.NewDirectoryInfo(_localAppDataFolder).Returns(new MockDirectoryInfo { FullName = _localAppDataFolder, Name = "DWGitsh" }); _config = Substitute.For <IDWGitshConfig>(); _config.AppDataFolder.Returns(_localAppDataFolder); _repoPaths = Substitute.For <IRepositoryPaths>(); _repoPaths.RootFolder.Returns("C:\\Junk\\Folder\\"); _repoPaths.RepositoryFolder.Returns("C:\\Junk\\Folder\\.git\\"); _hitRepo = Substitute.For <IHitDataRepo>(); _manager = new HitDataManager(_config, _diskManager, _repoPaths, null, _hitRepo); _hitRepo.Load().Returns(new CommandData()); }
protected GcdActionBase(string actionName, IRepositoryPaths repoPaths, IGitChangeDirectoryOptions options, IHitDataManager hitManager) { _hitManager = hitManager; _options = options; _repoPaths = repoPaths; this.ActionName = actionName; }
public HitDataManager(IDWGitshConfig config, IStaticAbstraction diskManager, IRepositoryPaths repoDirs, IGitUtils utils = null, IHitDataRepo hitRepo = null) { _utils = utils ?? GitUtils.Current; this._diskManager = diskManager ?? new StAbWrapper(); this.RepositoryDirectories = repoDirs; _hitDataRepo = hitRepo ?? new HitDataRepo(config.AppDataFolder, _diskManager); }
protected static GitFileEntry ParserFileLine(IRepositoryPaths repoDirs, string line) { var info = line.Trim(); if (string.IsNullOrWhiteSpace(info)) { return(null); } string relPath = null; string toPath = null; var defaultState = GitFileState.Unchanged; var splitPos = info.IndexOf(": "); if (splitPos > 0) { var changeType = info.Substring(0, splitPos); relPath = info.Substring(splitPos + 1).Trim(); if (changeType == "modified") { defaultState = GitFileState.Modified; } if (changeType == "deleted") { defaultState = GitFileState.Deleted; } if (changeType == "renamed") { defaultState = GitFileState.Renamed; } if (changeType == "copied") { defaultState = GitFileState.Copied; } var toPos = relPath.IndexOf("->"); if (toPos > 0) { toPath = relPath.Substring(toPos + 2).Trim(); relPath = relPath.Substring(0, toPos).Trim(); } } else { relPath = info; } var result = new GitFileEntry(repoDirs.CurrentPath, relPath, toPath) { State = defaultState }; return(result); }
public void Setup() { _hitManager = Substitute.For <IHitDataManager>(); _options = Substitute.For <IGitChangeDirectoryOptions>(); _diskManager = Substitute.For <IStaticAbstraction>(); _repoPaths = Substitute.For <IRepositoryPaths>(); _config = Substitute.For <IDWGitshConfig>(); _args = Substitute.For <IDWGitshCommonArgs>(); _args.DiskManager.Returns(_diskManager); _args.RepoPaths.Returns(_repoPaths); _args.Config.Returns(_config); }
private static void CalculateRelativePaths(IRepositoryPaths paths) { var curPath = paths?.CurrentPath; var root = paths?.RootFolder.TrimEnd(_seps); var relPath = BuildRelativePath(root, curPath); if (!string.IsNullOrEmpty(relPath)) { paths.RelativePathToRoot.Returns(relPath); var relRepoPath = PathJoin(relPath, ".git"); paths.RelativePathToRepository.Returns(relRepoPath); } }
protected void AddItemToCache(IRepositoryPaths repoDirs, string cacheName, TResult value) { if (this.CacheLinkFiles != null && this.CacheLinkFiles.Length > 0) { var tokens = new Dictionary <string, string>(); var curBranch = GitUtils.Current.GetBranchName(repoDirs); tokens.Add("{branchName}", curBranch); var linkedFiles = ResolveLinkedFiles(tokens); repoDirs.Cache.Add(cacheName, value, linkedFiles.ToArray()); } else if (this.CacheMaxAgeMinutes > 0) { var expSpan = new TimeSpan(0, Convert.ToInt32(this.CacheMaxAgeMinutes), 0); repoDirs.Cache.Add(cacheName, value, expSpan); } else { // Should this add a non-expiring item to the cache??? repoDirs.Cache.Add(cacheName, value); } }
protected void SetupBase() { _AllHitData = GcdTestHelper.BuildFakeHitData(); _info = new GitChangeDirectoryInfo(); _options = new GetGitChangeDirectoryCommandOptions(); _info.Options = new GetGitChangeDirectoryCommandOptions(); _repoPaths = Substitute.For <IRepositoryPaths>(); _repoPaths.RepositoryFolder.Returns(_gitFolder); _repoPaths.RootFolder.Returns(_rootFolder); _repoPathsNoGit = Substitute.For <IRepositoryPaths>(); _repoPathsNoGit.CurrentPath.Returns(_nonGitFolder); _hitManager = Substitute.For <IHitDataManager>(); _hitManager.GetHitList().Returns(_AllHitData); _lastHitFolder = _AllHitData.OrderByDescending(x => x.DateLastHit).First(); _hitManager.GetLastUsedFolder().Returns(_lastHitFolder.Directory); _hitManagerEmpty = Substitute.For <IHitDataManager>(); _hitManagerEmpty.GetHitList().Returns(new List <HitData>()); _hitManagerEmpty.GetLastUsedFolder().Returns((string)null); }
public string GetBranchName(IRepositoryPaths repoDirs) { string branch = null; var gitPath = repoDirs?.RepositoryFolder; if (!string.IsNullOrWhiteSpace(gitPath)) { var path = _diskManager.Path.Combine(gitPath, "HEAD"); if (_diskManager.File.Exists(path)) { var item = _diskManager.File.ReadAllText(path); if (!string.IsNullOrWhiteSpace(item)) { var pos = item.IndexOf("/heads/"); if (pos > 0) { branch = item.Substring(pos + 7).Trim(); } } } } return(branch); }
public DWGitshCommonArgs(IStaticAbstraction diskManager, IDWGitshConfig config, IRepositoryPaths repoPaths, IGitUtils utils, ICacheContainer cache) { this.DiskManager = diskManager ?? new StAbWrapper(); this.Config = config ?? new DWGitshConfig(DiskManager); this.Cache = cache ?? new CacheContainer(DiskManager); this.Utils = utils ?? new GitUtils(DiskManager, Cache); this.RepoPaths = repoPaths; }
public DWGitshCommonArgs(IStaticAbstraction diskManager, IDWGitshConfig config, IRepositoryPaths repoPaths, IGitUtils utils) : this(diskManager, config, repoPaths, utils, null) { }
public ActionLastDirectory(IRepositoryPaths repoPaths, IGitChangeDirectoryOptions options, IHitDataManager hitManager) : base("LastDirectory", repoPaths, options, hitManager) { }
public ActionRemoveAlias(IRepositoryPaths repoPaths, IGitChangeDirectoryOptions options, IHitDataManager hitManager) : base("Remove", repoPaths, options, hitManager) { }
protected ActionAlias(string actionName, IRepositoryPaths repoPaths, IGitChangeDirectoryOptions options, IHitDataManager hitManager) : base(actionName, repoPaths, options, hitManager) { TargetName = options.NameOrAlias; }
public ActionDefault(IRepositoryPaths repoPaths, IGitChangeDirectoryOptions options, IHitDataManager hitManager) : base("Default", repoPaths, options, hitManager) { }
public ActionNameOrAlias(IRepositoryPaths repoPaths, IGitChangeDirectoryOptions options, IHitDataManager hitManager) : base("NameOrAlias", repoPaths, options, hitManager) { this.RepositoryDirectories = repoPaths; }