Example #1
0
        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());
        }
Example #2
0
 protected GcdActionBase(string actionName, IRepositoryPaths repoPaths, IGitChangeDirectoryOptions options, IHitDataManager hitManager)
 {
     _hitManager     = hitManager;
     _options        = options;
     _repoPaths      = repoPaths;
     this.ActionName = actionName;
 }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        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);
            }
        }
Example #7
0
        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);
            }
        }
Example #8
0
        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);
        }
Example #9
0
        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);
        }
Example #10
0
        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;
        }
Example #11
0
 public DWGitshCommonArgs(IStaticAbstraction diskManager, IDWGitshConfig config, IRepositoryPaths repoPaths, IGitUtils utils) : this(diskManager, config, repoPaths, utils, null)
 {
 }
Example #12
0
 public ActionLastDirectory(IRepositoryPaths repoPaths, IGitChangeDirectoryOptions options, IHitDataManager hitManager)
     : base("LastDirectory", repoPaths, options, hitManager)
 {
 }
Example #13
0
 public ActionRemoveAlias(IRepositoryPaths repoPaths, IGitChangeDirectoryOptions options, IHitDataManager hitManager) : base("Remove", repoPaths, options, hitManager)
 {
 }
Example #14
0
 protected ActionAlias(string actionName, IRepositoryPaths repoPaths, IGitChangeDirectoryOptions options, IHitDataManager hitManager) : base(actionName, repoPaths, options, hitManager)
 {
     TargetName = options.NameOrAlias;
 }
Example #15
0
 public ActionDefault(IRepositoryPaths repoPaths, IGitChangeDirectoryOptions options, IHitDataManager hitManager)
     : base("Default", repoPaths, options, hitManager)
 {
 }
Example #16
0
 public ActionNameOrAlias(IRepositoryPaths repoPaths, IGitChangeDirectoryOptions options, IHitDataManager hitManager) : base("NameOrAlias", repoPaths, options, hitManager)
 {
     this.RepositoryDirectories = repoPaths;
 }