예제 #1
0
        /// <summary>Performs a cherry-pick operation on <paramref name="revisions"/>.</summary>
        /// <param name="revisions">Commits to cherry-pick.</param>
        public static void CherryPick(this IEnumerable <IRevisionPointer> revisions)
        {
            Verify.Argument.IsValidRevisionPointerSequence(revisions, "revisions");

            var        list       = new List <string>();
            Repository repository = null;

            foreach (var rev in revisions)
            {
                list.Add(rev.Pointer);
                repository = rev.Repository;
            }
            Verify.Argument.IsTrue(list.Count != 0, "revisions",
                                   Resources.ExcCollectionMustContainAtLeastOneObject.UseAsFormat("revision"));
            try
            {
                repository.Accessor.CherryPick.Invoke(new CherryPickParameters(list));
                repository.OnUpdated();
                repository.Head.NotifyRelogRecordAdded();
            }
            catch (AutomaticCherryPickFailedException)
            {
                repository.Status.Refresh();
                throw;
            }
        }
예제 #2
0
        public static Task FetchOrPullAsync(
            Repository repository, Remote remote, bool pull,
            IProgress <OperationProgress> progress, CancellationToken cancellationToken)
        {
            var affectedReferences = ReferenceType.RemoteBranch | ReferenceType.Tag;

            if (pull)
            {
                affectedReferences |= ReferenceType.LocalBranch;
            }
            var suppressedNotifications = repository.Monitor.BlockNotifications(
                RepositoryNotifications.BranchChanged, RepositoryNotifications.TagChanged);
            var  state1 = RefsState.Capture(repository, affectedReferences);
            Task task;

            if (pull)
            {
                var p = new PullParameters();
                if (remote != null)
                {
                    p.Repository = remote.Name;
                }
                task = repository.Accessor.Pull.InvokeAsync(p, progress, cancellationToken);
            }
            else
            {
                var p = new FetchParameters();
                if (remote != null)
                {
                    p.Repository = remote.Name;
                }
                task = repository.Accessor.Fetch.InvokeAsync(p, progress, cancellationToken);
            }
            return(task.ContinueWith(
                       t =>
            {
                progress.Report(new OperationProgress(Resources.StrRefreshingReferences.AddEllipsis()));
                repository.Refs.Refresh(affectedReferences);
                var state2 = RefsState.Capture(repository, affectedReferences);
                var changes = RefsDiff.Calculate(state1, state2);
                suppressedNotifications.Dispose();
                if (changes != null && changes.Length != 0)
                {
                    repository.OnUpdated();
                }
                TaskUtility.PropagateFaultedStates(t);
                if (pull)
                {
                    repository.Remotes.OnPullCompleted(remote, changes);
                }
                else
                {
                    repository.Remotes.OnFetchCompleted(remote, changes);
                }
            }));
        }
예제 #3
0
        public static void FetchOrPull(Repository repository, Remote remote, bool pull)
        {
            var affectedReferences = ReferenceType.RemoteBranch | ReferenceType.Tag;

            if (pull)
            {
                affectedReferences |= ReferenceType.LocalBranch;
            }
            ReferenceChange[] changes;
            var state1 = RefsState.Capture(repository, affectedReferences);

            using (repository.Monitor.BlockNotifications(
                       RepositoryNotifications.BranchChanged,
                       RepositoryNotifications.TagChanged))
            {
                try
                {
                    if (pull)
                    {
                        var p = new PullParameters();
                        if (remote != null)
                        {
                            p.Repository = remote.Name;
                        }
                        repository.Accessor.Pull.Invoke(p);
                    }
                    else
                    {
                        var p = new FetchParameters();
                        if (remote != null)
                        {
                            p.Repository = remote.Name;
                        }
                        repository.Accessor.Fetch.Invoke(p);
                    }
                }
                finally
                {
                    repository.Refs.Refresh(affectedReferences);
                    var state2 = RefsState.Capture(repository, affectedReferences);
                    changes = RefsDiff.Calculate(state1, state2);
                    if (changes != null && changes.Length != 0)
                    {
                        repository.OnUpdated();
                    }
                }
            }
            if (pull)
            {
                repository.Remotes.OnPullCompleted(remote, changes);
            }
            else
            {
                repository.Remotes.OnFetchCompleted(remote, changes);
            }
        }
예제 #4
0
 public static void FetchOrPull(Repository repository, Remote remote, bool pull)
 {
     var affectedReferences = ReferenceType.RemoteBranch | ReferenceType.Tag;
     if(pull)
     {
         affectedReferences |= ReferenceType.LocalBranch;
     }
     ReferenceChange[] changes;
     var state1 = RefsState.Capture(repository, affectedReferences);
     using(repository.Monitor.BlockNotifications(
         RepositoryNotifications.BranchChanged,
         RepositoryNotifications.TagChanged))
     {
         try
         {
             if(pull)
             {
                 var p = new PullParameters();
                 if(remote != null)
                 {
                     p.Repository = remote.Name;
                 }
                 repository.Accessor.Pull.Invoke(p);
             }
             else
             {
                 var p = new FetchParameters();
                 if(remote != null)
                 {
                     p.Repository = remote.Name;
                 }
                 repository.Accessor.Fetch.Invoke(p);
             }
         }
         finally
         {
             repository.Refs.Refresh(affectedReferences);
             var state2 = RefsState.Capture(repository, affectedReferences);
             changes = RefsDiff.Calculate(state1, state2);
             if(changes != null && changes.Length != 0)
             {
                 repository.OnUpdated();
             }
         }
     }
     if(pull)
     {
         repository.Remotes.OnPullCompleted(remote, changes);
     }
     else
     {
         repository.Remotes.OnFetchCompleted(remote, changes);
     }
 }
예제 #5
0
        public static void Revert(this IEnumerable <IRevisionPointer> revisions, bool noCommit)
        {
            Verify.Argument.IsValidRevisionPointerSequence(revisions, "revisions");

            var        list       = new List <string>();
            Repository repository = null;

            foreach (var rev in revisions)
            {
                list.Add(rev.Pointer);
                repository = rev.Repository;
            }
            Verify.Argument.IsTrue(list.Count != 0, "revisions",
                                   Resources.ExcCollectionMustContainAtLeastOneObject.UseAsFormat("revision"));

            var oldHeadRev = repository.Head.Revision;

            try
            {
                repository.Accessor.Revert.Invoke(
                    new RevertParameters(list, noCommit));
                if (!noCommit)
                {
                    var currentBranch = repository.Head.Pointer as Branch;
                    if (currentBranch != null)
                    {
                        currentBranch.Refresh();
                    }
                    else
                    {
                        repository.Head.Refresh();
                    }
                    var newHeadRev = repository.Head.Revision;
                    if (newHeadRev != oldHeadRev)
                    {
                        repository.OnUpdated();
                        repository.Head.NotifyRelogRecordAdded();
                    }
                }
            }
            catch (GitException)
            {
                repository.OnStateChanged();
                throw;
            }
            finally
            {
                repository.Status.Refresh();
            }
        }
예제 #6
0
 public static Task FetchOrPullAsync(
     Repository repository, Remote remote, bool pull,
     IProgress<OperationProgress> progress, CancellationToken cancellationToken)
 {
     var affectedReferences = ReferenceType.RemoteBranch | ReferenceType.Tag;
     if(pull)
     {
         affectedReferences |= ReferenceType.LocalBranch;
     }
     var suppressedNotifications = repository.Monitor.BlockNotifications(
         RepositoryNotifications.BranchChanged, RepositoryNotifications.TagChanged);
     var state1 = RefsState.Capture(repository, affectedReferences);
     Task task;
     if(pull)
     {
         var p = new PullParameters();
         if(remote != null)
         {
             p.Repository = remote.Name;
         }
         task = repository.Accessor.Pull.InvokeAsync(p, progress, cancellationToken);
     }
     else
     {
         var p = new FetchParameters();
         if(remote != null)
         {
             p.Repository = remote.Name;
         }
         task = repository.Accessor.Fetch.InvokeAsync(p, progress, cancellationToken);
     }
     return task.ContinueWith(
         t =>
         {
             progress.Report(new OperationProgress(Resources.StrRefreshingReferences.AddEllipsis()));
             repository.Refs.Refresh(affectedReferences);
             var state2 = RefsState.Capture(repository, affectedReferences);
             var changes = RefsDiff.Calculate(state1, state2);
             suppressedNotifications.Dispose();
             if(changes != null && changes.Length != 0)
             {
                 repository.OnUpdated();
             }
             TaskUtility.PropagateFaultedStates(t);
             if(pull)
             {
                 repository.Remotes.OnPullCompleted(remote, changes);
             }
             else
             {
                 repository.Remotes.OnFetchCompleted(remote, changes);
             }
         });
 }