Ejemplo n.º 1
0
        public RepoPaths GetRepoPaths(string currentPath, bool noCache)
        {
            if (string.IsNullOrWhiteSpace(currentPath))
            {
                throw new ArgumentException("Current path cannot be empty");
            }

            var       fixedCurPath = DWPSUtils.ForceTrailingSlash(currentPath);
            var       refCurPath   = "REF" + fixedCurPath;
            RepoPaths result       = null;

            if (!noCache)
            {
                result = RepoCache.Get <RepoPaths>(refCurPath);
            }

            if (result == null)
            {
                result = BuildRepoPaths(currentPath);
                RepoCache.Add(refCurPath, result, new TimeSpan(0, 10, 0), true);
            }

            result.IgnoreCache = noCache;

            return(result);
        }
Ejemplo n.º 2
0
        internal RepoPaths BuildRepoPaths(string currentPath)
        {
            var fixedCurPath = DWPSUtils.ForceTrailingSlash(currentPath);
            var result       = new RepoPaths {
                CurrentPath = fixedCurPath
            };
            var repoPath = GetPathToRepository(currentPath);

            if (!String.IsNullOrWhiteSpace(repoPath))
            {
                result.RootFolder               = DWPSUtils.ForceTrailingSlash(repoPath);
                result.RepositoryFolder         = DWPSUtils.ForceTrailingSlash(_diskManager.Path.Combine(result.RootFolder, ".git"));
                result.RelativePathToRoot       = DWPSUtils.BuildRelativePath(currentPath, result.RootFolder);
                result.RelativePathToRepository = DWPSUtils.BuildRelativePath(currentPath, result.RepositoryFolder);
            }

            var refPath = result.RootFolder ?? result.CurrentPath;

            var cache = RepoCache.Get <ICommandCache>(refPath);

            if (cache == null)
            {
                cache = new CommandCache();
                RepoCache.Add(refPath, cache);
            }

            result.Cache = cache;

            return(result);
        }
Ejemplo n.º 3
0
        protected static GitDetailModel BuildGitDetails(RepoPaths repoPaths, bool noCache)
        {
            var result = new GitDetailModel
            {
                Root = repoPaths.RootFolder,
                RelativePathToRoot = repoPaths.RelativePathToRoot
            };

            if (result.HasGit)
            {
                var configCmd = new GitConfigCommand(repoPaths, !noCache);
                var config    = configCmd.GetCommandResults();

                var statusCmd = new GitStatusCommand(repoPaths, !noCache);
                var status    = statusCmd.GetCommandResults();

                GetGitDir.TagRepoDir(config.RepoName, repoPaths.RootFolder);

                result.Branch     = GitUtils.Current.GetBranchName(repoPaths);
                result.User       = config?.User;
                result.Ahead      = (status?.Ahead) ?? 0;
                result.Behind     = (status?.Behind) ?? 0;
                result.Staged     = status?.Staged ?? 0;
                result.Unstaged   = status?.Unstaged ?? 0;
                result.IsDetached = status.Detached;
                result.DetachedAt = status.DetachedAt;

                result.FileChanges = status?.FileChanges;
            }

            return(result);
        }
Ejemplo n.º 4
0
 public GitConfigCommand(RepoPaths repoDirs, bool useCache = true) : base(repoDirs, useCache)
 {
     Name               = "Config";
     CacheName          = "config";
     Command            = "git --no-pager config --list";
     CacheMaxAgeMinutes = 10;
     Parser             = new GitConfigParser(this);
 }
Ejemplo n.º 5
0
        public GitStatusCommand(RepoPaths repoDirs, bool useCache = true) : base(repoDirs, useCache)
        {
            Name      = "Status";
            CacheName = "status";
            //Command = "git status --v";//  --ahead-behind";
            Command        = "git status";
            CacheLinkFiles = new string[] { "index", "FETCH_HEAD", "HEAD", "COMMIT_EDITMSG", "refs/remotes/origin/{branchName}" };
            Parser         = new GitStatusParser(this);

            CommandExecFolder = repoDirs.CurrentPath;
        }
Ejemplo n.º 6
0
        public void GetRepoPaths_usesCacheIfAvailable()
        {
            var currentPath  = "C:\\testZZZ\\badYYY\\folderNNN";
            var cacheFolders = new RepoPaths {
                CurrentPath = currentPath
            };
            var cacheKey = "REF" + currentPath + "\\";

            _cacheManager.Get <RepoPaths>(cacheKey).Returns(cacheFolders);

            DWPSUtils._diskManager = _diskManager;

            var result = _gitUtils.GetRepoPaths(currentPath, false);

            _cacheManager.Received(1).Get <RepoPaths>(cacheKey);
            Assert.IsNotNull(result);
            Assert.AreEqual(result.CurrentPath, currentPath);
            Assert.IsFalse(result.IgnoreCache);
        }
Ejemplo n.º 7
0
        protected void Init(IStaticAbstraction diskManager, IProcessManager processManager, RepoPaths repoDirs, bool useCache)
        {
            this._diskManager          = diskManager ?? new StAbWrapper();
            this._processManager       = processManager ?? new ProcessManager();
            this.RepositoryDirectories = repoDirs;
            this.UseCache = useCache;

            _colorGroups = new ColorGroupReader(_diskManager);

            FindAppDataFolder();
        }
Ejemplo n.º 8
0
 protected GitCommandBase(IStaticAbstraction diskManager, IProcessManager processManager, RepoPaths repoDirs, bool useCache = true)
 {
     Init(diskManager, processManager, repoDirs, useCache);
 }
Ejemplo n.º 9
0
 protected GitCommandBase(RepoPaths repoDirs, bool useCache)
 {
     Init(null, null, repoDirs, useCache);
 }
Ejemplo n.º 10
0
 protected GitCommandBase(RepoPaths repoDirs)
 {
     Init(null, null, repoDirs, !repoDirs.IgnoreCache);
 }