예제 #1
0
 IDisposable SetupProgressReporting() {
     var observable = _status.WhenAnyValue(x => x.Info);
     var observable2 = _status.WhenAnyValue(x => x.Action);
     _action = _status.Action;
     return new CompositeDisposable(observable2.Skip(1).Subscribe(ResetProgress),
         observable.Subscribe(x => WriteProgress(x.Action, x.Progress, x.Speed)), new RepoWatcher(_status));
 }
예제 #2
0
 public Status(string item, StatusRepo repo, double progress = 0, int speed = 0,
               TimeSpan?eta = null, RepoStatus action = RepoStatus.Waiting) : base(item, progress, speed, eta, action)
 {
     Repo = repo;
     Repo.AddItem(this);
     Color = "Green";
 }
예제 #3
0
        /// <summary>
        /// Gives the complete repository status
        /// </summary>
        /// <param name="org">Unique identifier of the organisation responsible for the app.</param>
        /// <param name="repository">The name of repository</param>
        /// <returns>The repository status</returns>
        public RepoStatus RepositoryStatus(string org, string repository)
        {
            RepoStatus repoStatus = new RepoStatus();

            repoStatus.ContentStatus = new List <RepositoryContent>();
            string localServiceRepoFolder = _settings.GetServicePath(org, repository, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext));

            using (var repo = new LibGit2Sharp.Repository(localServiceRepoFolder))
            {
                RepositoryStatus status = repo.RetrieveStatus(new LibGit2Sharp.StatusOptions());
                foreach (StatusEntry item in status)
                {
                    RepositoryContent content = new RepositoryContent();
                    content.FilePath   = item.FilePath;
                    content.FileStatus = (Altinn.Studio.Designer.Enums.FileStatus)(int) item.State;
                    if (content.FileStatus == Enums.FileStatus.Conflicted)
                    {
                        repoStatus.RepositoryStatus = Enums.RepositoryStatus.MergeConflict;
                        repoStatus.HasMergeConflict = true;
                    }

                    repoStatus.ContentStatus.Add(content);
                }

                LibGit2Sharp.Branch branch = repo.Branches.FirstOrDefault(b => b.IsTracking == true);
                if (branch != null)
                {
                    repoStatus.AheadBy  = branch.TrackingDetails.AheadBy;
                    repoStatus.BehindBy = branch.TrackingDetails.BehindBy;
                }
            }

            return(repoStatus);
        }
예제 #4
0
        private static void EnsureReposAreCleanAndUpToDate(IEnumerable <string> solutionPaths, string branch)
        {
            foreach (string solutionPath in solutionPaths)
            {
                Console.WriteLine($"Checking status of {solutionPath}.");

                if (GitUtility.IsGitRepo(solutionPath))
                {
                    string     currentBranch = GitUtility.GetCurrentBranch(solutionPath);
                    RepoStatus repoStatus    = GitUtility.GetRepoStatus(solutionPath);

                    if (currentBranch != branch)
                    {
                        throw new ExpectationFailedException($"{solutionPath} is checked out to {currentBranch}, expected {branch}.");
                    }

                    if (repoStatus != RepoStatus.CleanAndUpToDate)
                    {
                        throw new ExpectationFailedException($"{solutionPath} is not clean and up to date: {repoStatus.ToStatusString()}.");
                    }
                }
                else
                {
                    throw new ExpectationFailedException($"{solutionPath} is not a git repo.");
                }
            }

            Console.WriteLine();
        }
예제 #5
0
 public void Update()
 {
     IndexChanges    = X.Values.Aggregate(0, (a, b) => a + b) - X['?'] - X['A'] - X['D'] - X['↑'] - X['↓'];
     WorktreeChanges = Y.Values.Aggregate(0, (a, b) => a + b) - Y['?'] - Y['A'] - Y['D'];
     IndexAdded      = X['A'];
     IndexDeleted    = X['D'];
     WorktreeAdded   = Y['A'];
     WorktreeDeleted = Y['D'];
     Untracked       = X['?'];
     Behind          = X['↑'];
     Ahead           = X['↓'];
     RepoStatus      = RepoStatus.UpToDate;
     if ((IndexChanges > 0 || WorktreeChanges > 0 || WorktreeDeleted > 0 || IndexDeleted > 0) && Untracked == 0)
     {
         RepoStatus = RepoStatus.Modified;
     }
     if ((IndexChanges > 0 || WorktreeChanges > 0 || WorktreeDeleted > 0 || IndexDeleted > 0) && Untracked > 0)
     {
         RepoStatus = RepoStatus.ModifiedUntracked;
     }
     if (Behind > 0)
     {
         RepoStatus = RepoStatus.Behind;
     }
     if (Ahead > 0)
     {
         RepoStatus = RepoStatus.Ahead;
     }
     if (Ahead > 0 && Behind > 0)
     {
         RepoStatus = RepoStatus.AheadBehind;
     }
 }
예제 #6
0
 void WriteProgress(IStatus status)
 {
     _action = status.Action;
     Console.Write("\r" + status.Action + ":" + GetProgressComponent(status.Progress) +
                   GetSpeedComponent(status.Speed)
                   + "                    ");
 }
예제 #7
0
 /// <summary> Create repo update event arguments </summary>
 /// <param name="repoLocation">Repo location</param>
 /// <param name="oldStatus">Status before event</param>
 /// <param name="newStatus">Status after event</param>
 /// <param name="name">Name of repo</param>
 /// <param name="eventType"> Event type (add/remove/update) </param>
 public RepositoryEventArgs(string repoLocation, RepoStatus oldStatus, RepoStatus newStatus, string name, RepositoryEventType eventType)
 {
     Location  = repoLocation;
     OldStatus = oldStatus;
     NewStatus = newStatus;
     Name      = name;
     EventType = eventType;
 }
예제 #8
0
 public TransferStatus(string item, double progress = 0, int speed = 0,
     TimeSpan? eta = null, RepoStatus action = RepoStatus.Waiting) : this() {
     Item = item;
     _progress = progress;
     _speed = speed;
     _eta = eta;
     _action = action;
 }
예제 #9
0
 public TransferStatus(string item, double progress = 0, int speed = 0,
                       TimeSpan?eta = null, RepoStatus action      = RepoStatus.Waiting) : this()
 {
     Item      = item;
     _progress = progress;
     _speed    = speed;
     _eta      = eta;
     _action   = action;
 }
예제 #10
0
        static void Status(string patchFile, StatusRepo repo, Action <IStatus> act,
                           RepoStatus action = RepoStatus.Downloading)
        {
            var status = new Status(patchFile, repo)
            {
                Action = action
            };

            act(status);
            status.EndOutput();
        }
예제 #11
0
 public StatusInfo(RepoStatus action, double progress, long?speed, int?active, int done)
 {
     if (progress.Equals(double.NaN))
     {
         throw new ArgumentOutOfRangeException(nameof(progress));
     }
     Action   = action;
     Progress = progress;
     Speed    = speed;
     Active   = active;
     Done     = done;
 }
예제 #12
0
        public RepoStatus Pull(string owner, string repository)
        {
            RepoStatus pullStatus = _sourceControl.PullRemoteChanges(owner, repository);

            RepoStatus status = _sourceControl.RepositoryStatus(owner, repository);

            if (pullStatus.RepositoryStatus != Common.Enums.RepositoryStatus.Ok)
            {
                status.RepositoryStatus = pullStatus.RepositoryStatus;
            }

            return(status);
        }
예제 #13
0
 public static OverallStatusType ToOverallStatus(this RepoStatus status)
 {
     if (status >= RepoStatus.Mergeable)
     {
         return(OverallStatusType.CodeRed);
     }
     if (status >= RepoStatus.Behind)
     {
         return(OverallStatusType.WarnBehind);
     }
     if (status >= RepoStatus.Dirty)
     {
         return(OverallStatusType.WarnAhead);
     }
     return(OverallStatusType.Ok);
 }
예제 #14
0
        /// <summary>
        /// Gives the complete repository status
        /// </summary>
        /// <param name="owner">The owner of the repo, org or user</param>
        /// <param name="repository">The name of repository</param>
        /// <returns>The repository status</returns>
        public RepoStatus RepositoryStatus(string owner, string repository)
        {
            RepoStatus repoStatus = new RepoStatus();

            repoStatus.ContentStatus = new List <RepositoryContent>();
            string localServiceRepoFolder = _settings.GetServicePath(owner, repository, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext));

            using (var repo = new Repository(localServiceRepoFolder))
            {
                var watch = System.Diagnostics.Stopwatch.StartNew();
                RepositoryStatus status = repo.RetrieveStatus(new LibGit2Sharp.StatusOptions());
                watch.Stop();
                _logger.Log(Microsoft.Extensions.Logging.LogLevel.Information, "retrieverepostatusentries - {0} ", watch.ElapsedMilliseconds);

                watch = System.Diagnostics.Stopwatch.StartNew();
                foreach (StatusEntry item in status)
                {
                    RepositoryContent content = new RepositoryContent();
                    content.FilePath   = item.FilePath;
                    content.FileStatus = (AltinnCore.Common.Enums.FileStatus)(int) item.State;
                    if (content.FileStatus == Enums.FileStatus.Conflicted)
                    {
                        repoStatus.RepositoryStatus = Enums.RepositoryStatus.MergeConflict;
                        repoStatus.HasMergeConflict = true;
                    }

                    repoStatus.ContentStatus.Add(content);
                }

                watch.Stop();
                _logger.Log(Microsoft.Extensions.Logging.LogLevel.Information, "parsestatusentries - {0}", watch.ElapsedMilliseconds);

                watch = System.Diagnostics.Stopwatch.StartNew();
                Branch branch = repo.Branches.FirstOrDefault(b => b.IsTracking == true);
                if (branch != null)
                {
                    repoStatus.AheadBy  = branch.TrackingDetails.AheadBy;
                    repoStatus.BehindBy = branch.TrackingDetails.BehindBy;
                }

                watch.Stop();
                _logger.Log(Microsoft.Extensions.Logging.LogLevel.Information, "branch details - {0}", watch.ElapsedMilliseconds);
            }

            return(repoStatus);
        }
예제 #15
0
        /// <inheritdoc />
        public RepoStatus PullRemoteChanges(string org, string repository)
        {
            RepoStatus status = new RepoStatus();

            using (var repo = new LibGit2Sharp.Repository(FindLocalRepoLocation(org, repository)))
            {
                PullOptions pullOptions = new PullOptions()
                {
                    MergeOptions = new MergeOptions()
                    {
                        FastForwardStrategy = FastForwardStrategy.Default,
                    },
                };
                pullOptions.FetchOptions = new FetchOptions();
                pullOptions.FetchOptions.CredentialsProvider = (_url, _user, _cred) =>
                                                               new UsernamePasswordCredentials {
                    Username = GetAppToken(), Password = string.Empty
                };

                try
                {
                    MergeResult mergeResult = Commands.Pull(
                        repo,
                        new LibGit2Sharp.Signature("my name", "my email", DateTimeOffset.Now), // I dont want to provide these
                        pullOptions);

                    if (mergeResult.Status == MergeStatus.Conflicts)
                    {
                        status.RepositoryStatus = Enums.RepositoryStatus.MergeConflict;
                    }
                }
                catch (CheckoutConflictException e)
                {
                    _logger.LogError($"SourceControlSI // PullRemoteChanges // CheckoutConflictException occured when pulling repo {FindLocalRepoLocation(org, repository)}. {e}");
                    status.RepositoryStatus = Enums.RepositoryStatus.CheckoutConflict;
                }
                catch (Exception e)
                {
                    _logger.LogError($"SourceControlSI // PullRemoteChanges // Exception occured when pulling repo {FindLocalRepoLocation(org, repository)}. {e}");
                    throw;
                }
            }

            return(status);
        }
예제 #16
0
        /// <inheritdoc />
        public RepoStatus PullRemoteChanges(string org, string repository)
        {
            RepoStatus status = new RepoStatus();
            var        watch  = System.Diagnostics.Stopwatch.StartNew();

            using (var repo = new Repository(FindLocalRepoLocation(org, repository)))
            {
                PullOptions pullOptions = new PullOptions()
                {
                    MergeOptions = new MergeOptions()
                    {
                        FastForwardStrategy = FastForwardStrategy.Default,
                    },
                };

                pullOptions.FetchOptions = new FetchOptions();
                pullOptions.FetchOptions.CredentialsProvider = (_url, _user, _cred) =>
                                                               new UsernamePasswordCredentials {
                    Username = GetAppToken(), Password = string.Empty
                };

                try
                {
                    MergeResult mergeResult = Commands.Pull(
                        repo,
                        new LibGit2Sharp.Signature("my name", "my email", DateTimeOffset.Now), // I dont want to provide these
                        pullOptions);

                    if (mergeResult.Status == MergeStatus.Conflicts)
                    {
                        status.RepositoryStatus = Enums.RepositoryStatus.MergeConflict;
                    }
                }
                catch (LibGit2Sharp.CheckoutConflictException)
                {
                    status.RepositoryStatus = Enums.RepositoryStatus.CheckoutConflict;
                }
            }

            watch.Stop();
            _logger.Log(Microsoft.Extensions.Logging.LogLevel.Information, "pull - {0} ", watch.ElapsedMilliseconds);
            return(status);
        }
예제 #17
0
 public async Task CommitAsync(ICommandInput commands, string commitMessage)
 {
     await Task.Run(async() => {
         if (Status != RepoStatus.RepoFoundWithChanges)
         {
             return;
         }
         Status        = RepoStatus.ProcessingCommit;
         string toRun  = $"commit -a -m \"{commitMessage}\"";
         string result = await commands.RunProcessAsync("git", toRun);
         if (result.Contains(commitMessage))
         {
             Status = RepoStatus.CommitSucceeded;
         }
         else
         {
             Status = RepoStatus.CommitFailed;
         }
     });
 }
예제 #18
0
        private void UpdateRepoMenu(ToolStripItem menuItem, string repoName, RepoStatus status)
        {
            menuItem.Text = $"{repoName}: {Environment.NewLine}   {status}";

            if (status == RepoStatus.Conflict)
            {
                menuItem.BackColor = Color.FromArgb(0x80, Color.Red);
            }
            else if (status == RepoStatus.Behind)
            {
                menuItem.BackColor = Color.FromArgb(0x80, Color.Yellow);
            }
            else if (status == RepoStatus.Dirty)
            {
                menuItem.BackColor = Color.FromArgb(0x80, 0xB1, 0xB1, 0xFF);
            }
            else
            {
                menuItem.ResetBackColor();
            }
        }
예제 #19
0
 public async Task CommitAsync(ICommandInput commands, string commitMessage)
 {
     await Task.Run(async() => {
         if (Status != RepoStatus.RepoFoundWithChanges)
         {
             return;
         }
         Status       = RepoStatus.ProcessingCommit;
         string toRun = $"commit -m \"{commitMessage}\"";
         //Add new files to repo and remove deleted files from repo.
         await commands.RunProcessAsync("hg", "addremove");
         string result = await commands.RunProcessAsync("hg", toRun);
         if (String.IsNullOrWhiteSpace(result))
         {
             Status = RepoStatus.CommitSucceeded;
         }
         else
         {
             Status = RepoStatus.CommitFailed;
         }
     });
 }
예제 #20
0
        public bool Exists(ICommandInput commands)
        {
            Task <string> task = commands.RunProcessAsync("git", "status");

            task.Wait();
            string result = task.Result;

            task.Dispose();
            if (result.Contains(GitMessageNoRepo))
            {
                Status = RepoStatus.NoRepoFound;
                return(false);
            }
            else if (String.IsNullOrWhiteSpace(result))
            {
                Status = RepoStatus.RepoFoundNoChanges;
            }
            else
            {
                Status = RepoStatus.RepoFoundWithChanges;
            }
            return(true);
        }
 static void Status(string patchFile, StatusRepo repo, Action<IStatus> act,
     RepoStatus action = RepoStatus.Downloading) {
     var status = new Status(patchFile, repo) {Action = action};
     act(status);
     status.EndOutput();
 }
예제 #22
0
 public void Reset(RepoStatus action) => _wrapped.Reset(action);
예제 #23
0
 public Status(string item, StatusRepo repo, double progress = 0, int speed = 0,
     TimeSpan? eta = null, RepoStatus action = RepoStatus.Waiting) : base(item, progress, speed, eta, action) {
     Repo = repo;
     Repo.AddItem(this);
     Color = "Green";
 }
예제 #24
0
 void ResetProgress(RepoStatus newAction) {
     System.Console.Write(FillWithSpaceNl(string.Format("\r{0}: 100%", _action)));
 }
예제 #25
0
 void WriteProgress(RepoStatus action, double progress, long speed) {
     _action = action;
     var line = action + ":" + GetProgressComponent(progress) + GetSpeedComponent(speed)
                + GetItemComponent(_status);
     System.Console.Write(FillWithSpace("\r" + line));
 }
예제 #26
0
 protected void ResetProgress(RepoStatus newAction)
 {
     ResetP(_action);
 }
예제 #27
0
 public void Reset(RepoStatus action)
 {
     Reset();
     Action = action;
 }
 public void Start(RepoStatus action = RepoStatus.Downloading) {
     if (Progress != null) {
         Progress.StartOutput(LocalFile.ToString());
         Progress.Action = action;
     }
 }
예제 #29
0
 void WriteProgress(IStatus status) {
     _action = status.Action;
     Console.Write("\r" + status.Action + ":" + GetProgressComponent(status.Progress) +
                   GetSpeedComponent(status.Speed)
                   + "                    ");
 }
예제 #30
0
 protected void ResetProgress(RepoStatus newAction) {
     ResetP(_action);
 }
예제 #31
0
 public ConsoleTransferProgress(IStatusItem status) {
     _status = status;
     _action = status.State.Action;
 }
예제 #32
0
 protected static void ResetP(RepoStatus action) {
     Console.Write("\r{0}: 100%                                                                       \n", action);
 }
예제 #33
0
 public void Reset(RepoStatus action) {
     Reset();
     Action = action;
 }
예제 #34
0
 public void ResetWithoutClearItems(RepoStatus status, int total)
 {
     Total  = total;
     Action = status;
     UpdateData(0, 0, 0, 0);
 }
예제 #35
0
 public ConsoleProgress(StatusRepo status) {
     _status = status;
     _action = status.Action;
     _disposable = SetupProgressReporting();
 }
예제 #36
0
 public void Reset(RepoStatus status, int total)
 {
     lock (Items)
         Items.Clear();
     ResetWithoutClearItems(status, total);
 }
예제 #37
0
 public void Reset(RepoStatus action = RepoStatus.Processing) {
     UpdateData(0, 0);
     Action = action;
 }
예제 #38
0
 public ConsoleTransferProgress(IStatusItem status)
 {
     _status = status;
     _action = status.State.Action;
 }
예제 #39
0
 protected static void ResetP(RepoStatus action)
 {
     Console.Write("\r{0}: 100%                                                                       \n", action);
 }