Пример #1
0
        public void GetDeps()
        {
            rootRepo        = new GitRepository(rootModule.Name, Helper.CurrentWorkspace, Log);
            rootRepoTreeish = rootRepo.CurrentLocalTreeish().Value;

            var depsContent = new DepsParser(rootRepo.RepoPath).Get(rootModule.Configuration);

            if (!Directory.Exists(Path.Combine(Helper.CurrentWorkspace, "nuget")) &&
                modules.Any(m => m.Name == "nuget"))
            {
                depsContent.Deps.Add(new Dep("nuget"));
            }

            depsContent.Force = Helper.DefineForce(depsContent.Force, rootRepo);
            Log.Info("OK");

            var queue = new DepsQueue();

            queue.AddRange(depsContent.Deps, rootModule.Name);

            var proceed = new ModulesContainer();

            GetDeps(depsContent.Force, queue, proceed);

            CycleDetector.WarnIfCycle(rootModule.Name, rootModule.Configuration, Log);
        }
Пример #2
0
        public static string DefineForce(string force, GitRepository rootRepo)
        {
            if (force == null || !force.Contains("->") && !force.Contains("CURRENT_BRANCH"))
            {
                return(force);
            }
            if (force.Equals("%CURRENT_BRANCH%") || force.Equals("$CURRENT_BRANCH"))
            {
                return(rootRepo.CurrentLocalTreeish().Value);
            }

            return(null);
        }
Пример #3
0
        public void GetDeps()
        {
            rootRepo        = new GitRepository(rootModule.Name, Helper.CurrentWorkspace, Log);
            rootRepoTreeish = rootRepo.CurrentLocalTreeish().Value;

            var depsContent = new DepsParser(rootRepo.RepoPath).Get(rootModule.Configuration);

            depsContent.Force = depsContent.Force?.Select(f => Helper.DefineForce(f, rootRepo)).ToArray();
            Log.LogInformation("OK");

            var queue = new DepsQueue();

            queue.AddRange(depsContent.Deps, rootModule.Name);

            var proceed = new ModulesContainer();

            GetDeps(depsContent.Force, queue, proceed);

            CycleDetector.WarnIfCycle(rootModule.Name, rootModule.Configuration, Log);
        }
Пример #4
0
        private void GetTreeish(GitRepository repo, Dep dep, string force, string treeish, GetInfo getInfo)
        {
            treeish = treeish ?? "master";
            Log.Info($"{"[" + dep.Name + "]",-30}Getting treeish '{treeish}'");

            var hasRemoteBranch = repo.HasRemoteBranch(treeish);

            getInfo.Forced = HaveToForce(dep, force, repo);
            if (getInfo.Forced)
            {
                treeish = force;
                Log.Info($"{"[" + dep.Name + "]",-30}treeish '{treeish}' was forced");
            }

            ConsoleWriter.WriteProgress(dep.Name + "/" + dep.Configuration + "\t" + treeish);

            var oldSha    = repo.SafeGetCurrentLocalCommitHash();
            var remoteSha = repo.HasRemoteBranch(treeish) ? repo.RemoteCommitHashAtBranch(treeish) : treeish;

            var localChangesAction = DefineLocalChangesPolicy(repo, oldSha, remoteSha);

            if (localChangesAction == LocalChangesAction.ForceLocal)
            {
                getInfo.ForcedLocal = true;
                return;
            }

            if (localChangesAction == LocalChangesAction.Reset)
            {
                Reset(repo, dep);
                getInfo.Reset = true;
            }

            ConsoleWriter.WriteProgress(dep.Name + " looking for remote commit hash");
            if (hasRemoteBranch && repo.RemoteCommitHashAtBranch(treeish).Equals(oldSha) && repo.CurrentLocalTreeish().Value.Equals(treeish))
            {
                return;
            }

            if (repo.HasLocalBranch(treeish))
            {
                ConsoleWriter.WriteProgress(dep.Name + " has local branch " + treeish);
                Log.Info($"{"[" + dep.Name + "]",-30}has local branch '{treeish}'");

                ConsoleWriter.WriteProgress(dep.Name + " checkout " + treeish);
                repo.Checkout(treeish);
                if (hasRemoteBranch)
                {
                    if (userLocalChangesPolicy == LocalChangesPolicy.Reset && !repo.FastForwardPullAllowed(treeish))
                    {
                        repo.ResetHard(treeish);
                    }
                    else
                    {
                        ConsoleWriter.WriteProgress(dep.Name + " pull " + treeish);
                        repo.Pull(treeish);
                    }
                }
            }
            else
            {
                Log.Info($"{"[" + dep.Name + "]",-30}doesn't have local branch '{treeish}'");
                ConsoleWriter.WriteProgress(dep.Name + " fetch " + treeish);
                if (repo.HasRemoteBranch(treeish))
                {
                    repo.Fetch(treeish);
                }
                else
                {
                    repo.Fetch("");
                }
                ConsoleWriter.WriteProgress(dep.Name + " checkout " + treeish);
                repo.Checkout(treeish);
            }

            var newSha = repo.CurrentLocalCommitHash();

            getInfo.Reset = false;

            if (userLocalChangesPolicy == LocalChangesPolicy.Reset && hasRemoteBranch &&
                !repo.RemoteCommitHashAtBranch(treeish).Equals(newSha))
            {
                repo.ResetHard(treeish);
                getInfo.Reset = true;
            }
            getInfo.Changed = !oldSha.Equals(newSha);
            getInfo.Pulled  = localChangesAction == LocalChangesAction.Pull;
        }