示例#1
0
        /// <summary>
        /// Start a rebase operation.
        /// </summary>
        /// <param name="branch">The branch to rebase.</param>
        /// <param name="upstream">The starting commit to rebase.</param>
        /// <param name="onto">The branch to rebase onto.</param>
        /// <param name="committer">The <see cref="Identity"/> of who added the change to the repository.</param>
        /// <param name="options">The <see cref="RebaseOptions"/> that specify the rebase behavior.</param>
        /// <returns>true if completed successfully, false if conflicts encountered.</returns>
        public virtual RebaseResult Start(Branch branch, Branch upstream, Branch onto, Identity committer, RebaseOptions options)
        {
            Ensure.ArgumentNotNull(upstream, "upstream");

            options = options ?? new RebaseOptions();

            EnsureNonBareRepo();

            if (this.repository.Info.CurrentOperation != CurrentOperation.None)
            {
                throw new LibGit2SharpException("A {0} operation is already in progress.",
                                                this.repository.Info.CurrentOperation);
            }

            Func <Branch, ReferenceHandle> RefHandleFromBranch = (Branch b) =>
            {
                return((b == null) ?
                       null :
                       this.repository.Refs.RetrieveReferencePtr(b.CanonicalName));
            };

            using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options))
            {
                GitRebaseOptions gitRebaseOptions = new GitRebaseOptions()
                {
                    version          = 1,
                    checkout_options = checkoutOptionsWrapper.Options,
                };

                using (ReferenceHandle branchRefPtr = RefHandleFromBranch(branch))
                    using (ReferenceHandle upstreamRefPtr = RefHandleFromBranch(upstream))
                        using (ReferenceHandle ontoRefPtr = RefHandleFromBranch(onto))
                            using (AnnotatedCommitHandle annotatedBranchCommitHandle = AnnotatedCommitHandleFromRefHandle(branchRefPtr))
                                using (AnnotatedCommitHandle upstreamRefAnnotatedCommitHandle = AnnotatedCommitHandleFromRefHandle(upstreamRefPtr))
                                    using (AnnotatedCommitHandle ontoRefAnnotatedCommitHandle = AnnotatedCommitHandleFromRefHandle(ontoRefPtr))
                                        using (RebaseHandle rebaseOperationHandle = Proxy.git_rebase_init(this.repository.Handle,
                                                                                                          annotatedBranchCommitHandle,
                                                                                                          upstreamRefAnnotatedCommitHandle,
                                                                                                          ontoRefAnnotatedCommitHandle,
                                                                                                          gitRebaseOptions))
                                        {
                                            RebaseResult rebaseResult = RebaseOperationImpl.Run(rebaseOperationHandle,
                                                                                                this.repository,
                                                                                                committer,
                                                                                                options);
                                            return(rebaseResult);
                                        }
            }
        }
示例#2
0
        internal virtual RebaseResult Start(ReferenceHandle annotatedRefPtr, ReferenceHandle upstreamRefPtr, ReferenceHandle ontoRefPtr, Identity committer, RebaseOptions options)
        {
            Ensure.ArgumentNotNull(upstreamRefPtr, "upstream");

            options = options ?? new RebaseOptions();

            EnsureNonBareRepo();

            if (this.repository.Info.CurrentOperation != CurrentOperation.None)
            {
                throw new LibGit2SharpException("A {0} operation is already in progress.",
                                                this.repository.Info.CurrentOperation);
            }

            using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options))
            {
                GitRebaseOptions gitRebaseOptions = new GitRebaseOptions()
                {
                    version          = 1,
                    checkout_options = checkoutOptionsWrapper.Options,
                };

                using (AnnotatedCommitHandle annotatedBranchCommitHandle = AnnotatedCommitHandleFromRefHandle(annotatedRefPtr))
                    using (AnnotatedCommitHandle upstreamRefAnnotatedCommitHandle = AnnotatedCommitHandleFromRefHandle(upstreamRefPtr))
                        using (AnnotatedCommitHandle ontoRefAnnotatedCommitHandle = AnnotatedCommitHandleFromRefHandle(ontoRefPtr))
                            using (RebaseHandle rebaseOperationHandle = Proxy.git_rebase_init(this.repository.Handle,
                                                                                              annotatedBranchCommitHandle,
                                                                                              upstreamRefAnnotatedCommitHandle,
                                                                                              ontoRefAnnotatedCommitHandle,
                                                                                              gitRebaseOptions))
                            {
                                this.repository.Submodules.UpdateAll(options.SubmoduleUpdateOptions);

                                RebaseResult rebaseResult = RebaseOperationImpl.Run(rebaseOperationHandle,
                                                                                    this.repository,
                                                                                    committer,
                                                                                    options);
                                return(rebaseResult);
                            }
            }
        }