internal VersionControlSystem(IVersionControlSystemOptions options, ITerminal terminal)
 {
     Options     = options;
     Terminal    = terminal;
     _repoRoot   = new Lazy <string>(() => !Options.RepoRoot.RemoveAllWhiteSpace().Equals(string.Empty) ? FileSystem.NormalizedPath(Options.RepoRoot) : FileSystem.NormalizedPath("."));
     _sourceCode = new Lazy <IEnumerable <string> >(LoadSourceCode);
 }
示例#2
0
        public static IVersionControlSystem Create(IVersionControlSystemOptions options, ITerminal terminal)
        {
            var versionControlSystems = new[] { new Git(options, terminal) };
            var vcs = versionControlSystems.FirstOrDefault(x => x.Detecter);

            return(vcs ?? new VersionControlSystem(options, terminal));
        }
示例#3
0
 public Git(IVersionControlSystemOptions options, ITerminal terminal)
     : base(options, terminal)
 {
     _branch     = new Lazy <string>(LoadBranch);
     _commit     = new Lazy <string>(LoadCommit);
     _repoRoot   = new Lazy <string>(LoadRepoRoot);
     _slug       = new Lazy <string>(LoadSlug);
     _sourceCode = new Lazy <IEnumerable <string> >(LoadSourceCode);
     _detecter   = new Lazy <bool>(LoadDetecter);
 }
        public static IVersionControlSystem Create(IVersionControlSystemOptions options, ITerminal terminal)
        {
            var assembly      = typeof(VersionControlSystemFactory).Assembly;
            var interfaceType = typeof(IVersionControlSystem);

            var versionControlSystems = assembly.GetTypes().Where(t => t.IsClass && !t.IsAbstract && interfaceType.IsAssignableFrom(t) && t != typeof(VersionControlSystem));
            var vcs = GetFirstDetectedVcsSystem(versionControlSystems, options, terminal);

            return(vcs ?? new VersionControlSystem(options, terminal));
        }
        private static IVersionControlSystem GetFirstDetectedVcsSystem(IEnumerable <Type> supportedVcs, IVersionControlSystemOptions options, ITerminal terminal)
        {
            foreach (var t in supportedVcs)
            {
                var csi = t.GetConstructor(new[] { typeof(IVersionControlSystemOptions), typeof(ITerminal) });

                if (csi is null)
                {
                    continue;
                }

                var buildServer = (IVersionControlSystem)csi.Invoke(new object[] { options, terminal });
                if (buildServer.Detecter)
                {
                    return(buildServer);
                }
            }

            return(new VersionControlSystem(options, terminal));
        }