Пример #1
0
        async Task CalculateGitUpdates(MicroserviceItem service)
        {
            if (service.WebsiteFolder.IsEmpty())
            {
                return;
            }
            service.RollProgress($"Fetch '{service.Service}' local git updates ...");
            var projFOlder = service.WebsiteFolder.AsDirectory().Parent;

            if (projFOlder == null || !Directory.Exists(Path.Combine(projFOlder.FullName, ".git")))
            {
                return;
            }

            service.GitUpdates = "0";
            try
            {
                var fetchoutput = "git.exe".AsFile(searchEnvironmentPath: true)
                                  .Execute("fetch", waitForExit: true, configuration: x => x.StartInfo.WorkingDirectory = projFOlder.FullName);

                service.LogMessage($"git fetch completed ... ({service.Service})");

                var output = "git.exe".AsFile(searchEnvironmentPath: true)
                             .Execute("status", waitForExit: true, configuration: x => x.StartInfo.WorkingDirectory = projFOlder.FullName);

                var status = ReadGitInfo(output);
                if (status != null && status.GitRemoteCommits > 0)
                {
                    service.LogMessage($"There are {status.GitRemoteCommits} git commit(s) available to update .");
                }

                service.GitUpdates = status?.GitRemoteCommits.ToString();
            }
            catch (Exception e)
            {
                service.LogMessage("Error on git command ...", e.Message);
                service.StopProgress($"Error on git command, please open the '{service}' log window for detail.");
            }

            service.GitUpdateIsInProgress = false;
            service.StopProgress();
        }
        void LocalGitChanges(MicroserviceItem service)
        {
            service.LocalGitChanges = "...";
            service.LocalGitTooltip = "no changes.";

            if (service.WebsiteFolder.IsEmpty())
            {
                return;
            }

            var projFOlder = service.WebsiteFolder.AsDirectory().Parent;

            if (projFOlder == null || !Directory.Exists(Path.Combine(projFOlder.FullName, ".git")))
            {
                return;
            }

            try
            {
                var fetchoutput = "git.exe".AsFile(searchEnvironmentPath: true)
                                  .Execute("status --short", waitForExit: true, configuration: x => x.StartInfo.WorkingDirectory = projFOlder.FullName);

                var changes = new List <string>(
                    fetchoutput.Split(new string[] { "\r\n" },
                                      StringSplitOptions.RemoveEmptyEntries)).Count();

                if (changes > 0)
                {
                    service.LocalGitChanges = changes.ToString();
                }

                service.LocalGitTooltip = changes > 0 ? changes.ToString() + " uncommited changes." : "no changes.";
            }
            catch (Exception e)
            {
                service.LogMessage("Error on git command ...", e.Message);
            }
        }