Exemplo n.º 1
0
        private static RebaseStepResult ApplyPickStep(RebaseHandle rebaseOperationHandle, Repository repository, Identity committer, RebaseOptions options, RebaseStepInfo stepToApplyInfo)
        {
            RebaseStepResult rebaseStepResult;

            // commit and continue.
            if (repository.Index.IsFullyMerged)
            {
                Proxy.GitRebaseCommitResult rebase_commit_result = Proxy.git_rebase_commit(rebaseOperationHandle, null, committer);

                if (rebase_commit_result.WasPatchAlreadyApplied)
                {
                    rebaseStepResult = new RebaseStepResult(RebaseStepStatus.ChangesAlreadyApplied);
                }
                else
                {
                    rebaseStepResult = new RebaseStepResult(RebaseStepStatus.Committed, rebase_commit_result.CommitId);
                }
            }
            else
            {
                rebaseStepResult = new RebaseStepResult(RebaseStepStatus.Conflicts);
            }

            return rebaseStepResult;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Run a rebase to completion, a conflict, or a requested stop point.
        /// </summary>
        /// <param name="rebaseOperationHandle">Handle to the rebase operation.</param>
        /// <param name="repository">Repository in which rebase operation is being run.</param>
        /// <param name="committer">Committer Identity to use for the rebased commits.</param>
        /// <param name="options">Options controlling rebase behavior.</param>
        /// <returns>RebaseResult that describes the result of the rebase operation.</returns>
        public static RebaseResult Run(RebaseSafeHandle rebaseOperationHandle,
                                       Repository repository,
                                       Identity committer,
                                       RebaseOptions options)
        {
            Ensure.ArgumentNotNull(rebaseOperationHandle, "rebaseOperationHandle");
            Ensure.ArgumentNotNull(repository, "repository");
            Ensure.ArgumentNotNull(committer, "committer");
            Ensure.ArgumentNotNull(options, "options");

            RebaseResult rebaseResult = null;

            // This loop will run until a rebase result has been set.
            while (rebaseResult == null)
            {
                RebaseProgress rebaseStepContext = NextRebaseStep(repository, rebaseOperationHandle);

                if (rebaseStepContext.current != -1)
                {
                    rebaseResult = RunRebaseStep(rebaseOperationHandle,
                                                 repository,
                                                 committer,
                                                 options,
                                                 rebaseStepContext.current,
                                                 rebaseStepContext.total);
                }
                else
                {
                    // No step to apply - need to complete the rebase.
                    rebaseResult = CompleteRebase(rebaseOperationHandle, committer);
                }
            }

            return(rebaseResult);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Run a rebase to completion, a conflict, or a requested stop point.
        /// </summary>
        /// <param name="rebaseOperationHandle">Handle to the rebase operation.</param>
        /// <param name="repository">Repository in which rebase operation is being run.</param>
        /// <param name="committer">Committer Identity to use for the rebased commits.</param>
        /// <param name="options">Options controlling rebase behavior.</param>
        /// <returns>RebaseResult that describes the result of the rebase operation.</returns>
        public static RebaseResult Run(RebaseHandle rebaseOperationHandle,
            Repository repository,
            Identity committer,
            RebaseOptions options)
        {
            Ensure.ArgumentNotNull(rebaseOperationHandle, "rebaseOperationHandle");
            Ensure.ArgumentNotNull(repository, "repository");
            Ensure.ArgumentNotNull(committer, "committer");
            Ensure.ArgumentNotNull(options, "options");

            RebaseResult rebaseResult = null;

            // This loop will run until a rebase result has been set.
            while (rebaseResult == null)
            {
                RebaseProgress rebaseStepContext = NextRebaseStep(repository, rebaseOperationHandle);

                if (rebaseStepContext.current != -1)
                {
                    rebaseResult = RunRebaseStep(rebaseOperationHandle,
                                                   repository,
                                                   committer,
                                                   options,
                                                   rebaseStepContext.current,
                                                   rebaseStepContext.total);
                }
                else
                {
                    // No step to apply - need to complete the rebase.
                    rebaseResult = CompleteRebase(rebaseOperationHandle, committer);
                }
            }

            return rebaseResult;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Continue the current rebase.
        /// </summary>
        /// <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>
        public virtual unsafe RebaseResult Continue(Identity committer, RebaseOptions options)
        {
            Ensure.ArgumentNotNull(committer, "committer");

            options = options ?? new RebaseOptions();

            EnsureNonBareRepo();

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

                using (RebaseHandle rebase = Proxy.git_rebase_open(repository.Handle, gitRebaseOptions))
                {
                    // TODO: Should we check the pre-conditions for committing here
                    // for instance - what if we had failed on the git_rebase_finish call,
                    // do we want continue to be able to restart afterwords...
                    var rebaseCommitResult = Proxy.git_rebase_commit(rebase, null, committer);

                    // Report that we just completed the step
                    if (options.RebaseStepCompleted != null)
                    {
                        // Get information on the current step
                        long currentStepIndex = Proxy.git_rebase_operation_current(rebase);
                        long totalStepCount   = Proxy.git_rebase_operation_entrycount(rebase);
                        git_rebase_operation *gitRebasestepInfo = Proxy.git_rebase_operation_byindex(rebase, currentStepIndex);

                        var stepInfo = new RebaseStepInfo(gitRebasestepInfo->type,
                                                          repository.Lookup <Commit>(ObjectId.BuildFromPtr(&gitRebasestepInfo->id)),
                                                          LaxUtf8NoCleanupMarshaler.FromNative(gitRebasestepInfo->exec));

                        if (rebaseCommitResult.WasPatchAlreadyApplied)
                        {
                            options.RebaseStepCompleted(new AfterRebaseStepInfo(stepInfo, currentStepIndex, totalStepCount));
                        }
                        else
                        {
                            options.RebaseStepCompleted(new AfterRebaseStepInfo(stepInfo,
                                                                                repository.Lookup <Commit>(new ObjectId(rebaseCommitResult.CommitId)),
                                                                                currentStepIndex,
                                                                                totalStepCount));
                        }
                    }

                    RebaseResult rebaseResult = RebaseOperationImpl.Run(rebase, repository, committer, options);
                    return(rebaseResult);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Abort the rebase operation.
        /// </summary>
        /// <param name="options">The <see cref="RebaseOptions"/> that specify the rebase behavior.</param>
        public virtual void Abort(RebaseOptions options)
        {
            options = options ?? new RebaseOptions();

            EnsureNonBareRepo();

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

                using (RebaseHandle rebase = Proxy.git_rebase_open(repository.Handle, gitRebaseOptions))
                {
                    Proxy.git_rebase_abort(rebase);
                }
            }
        }
Exemplo n.º 6
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);
                                        }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Run the current rebase step. This will handle reporting that we are about to run a rebase step,
        /// identifying and running the operation for the current step, and reporting the current step is completed.
        /// </summary>
        /// <param name="rebaseOperationHandle"></param>
        /// <param name="repository"></param>
        /// <param name="committer"></param>
        /// <param name="options"></param>
        /// <param name="stepToApplyIndex"></param>
        /// <param name="totalStepCount"/>
        /// <returns></returns>
        private static RebaseResult RunRebaseStep(RebaseSafeHandle rebaseOperationHandle,
                                                  Repository repository,
                                                  Identity committer,
                                                  RebaseOptions options,
                                                  long stepToApplyIndex,
                                                  long totalStepCount)
        {
            RebaseStepResult rebaseStepResult     = null;
            RebaseResult     rebaseSequenceResult = null;

            GitRebaseOperation rebaseOp = Proxy.git_rebase_operation_byindex(rebaseOperationHandle, stepToApplyIndex);
            ObjectId           idOfCommitBeingRebased = new ObjectId(rebaseOp.id);

            RebaseStepInfo stepToApplyInfo = new RebaseStepInfo(rebaseOp.type,
                                                                repository.Lookup <Commit>(idOfCommitBeingRebased),
                                                                LaxUtf8NoCleanupMarshaler.FromNative(rebaseOp.exec));

            // Report the rebase step we are about to perform.
            if (options.RebaseStepStarting != null)
            {
                options.RebaseStepStarting(new BeforeRebaseStepInfo(stepToApplyInfo, stepToApplyIndex, totalStepCount));
            }

            // Perform the rebase step
            GitRebaseOperation rebaseOpReport = Proxy.git_rebase_next(rebaseOperationHandle);

            // Verify that the information from the native library is consistent.
            VerifyRebaseOp(rebaseOpReport, stepToApplyInfo);

            // Handle the result
            switch (stepToApplyInfo.Type)
            {
            case RebaseStepOperation.Pick:
                rebaseStepResult = ApplyPickStep(rebaseOperationHandle, repository, committer, options, stepToApplyInfo);
                break;

            case RebaseStepOperation.Squash:
            case RebaseStepOperation.Edit:
            // case RebaseStepOperation.Exec:
            case RebaseStepOperation.Fixup:
            case RebaseStepOperation.Reword:
                // These operations are not yet supported by lg2.
                throw new LibGit2SharpException("Rebase Operation Type ({0}) is not currently supported in LibGit2Sharp.",
                                                stepToApplyInfo.Type);

            default:
                throw new ArgumentException(string.Format(
                                                "Unexpected Rebase Operation Type: {0}", stepToApplyInfo.Type));
            }

            // Report that we just completed the step
            if (options.RebaseStepCompleted != null &&
                (rebaseStepResult.Status == RebaseStepStatus.Committed ||
                 rebaseStepResult.Status == RebaseStepStatus.ChangesAlreadyApplied))
            {
                if (rebaseStepResult.ChangesAlreadyApplied)
                {
                    options.RebaseStepCompleted(new AfterRebaseStepInfo(stepToApplyInfo, stepToApplyIndex, totalStepCount));
                }
                else
                {
                    options.RebaseStepCompleted(new AfterRebaseStepInfo(stepToApplyInfo,
                                                                        repository.Lookup <Commit>(new ObjectId(rebaseStepResult.CommitId)),
                                                                        stepToApplyIndex,
                                                                        totalStepCount));
                }
            }

            // If the result of the rebase step is something that requires us to stop
            // running the rebase sequence operations, then report the result.
            if (rebaseStepResult.Status == RebaseStepStatus.Conflicts)
            {
                rebaseSequenceResult = new RebaseResult(RebaseStatus.Conflicts,
                                                        stepToApplyIndex,
                                                        totalStepCount,
                                                        null);
            }

            return(rebaseSequenceResult);
        }
Exemplo n.º 8
0
        private static RebaseStepResult ApplyPickStep(RebaseSafeHandle rebaseOperationHandle, Repository repository, Identity committer, RebaseOptions options, RebaseStepInfo stepToApplyInfo)
        {
            RebaseStepResult rebaseStepResult;

            // commit and continue.
            if (repository.Index.IsFullyMerged)
            {
                Proxy.GitRebaseCommitResult rebase_commit_result = Proxy.git_rebase_commit(rebaseOperationHandle, null, committer);

                if (rebase_commit_result.WasPatchAlreadyApplied)
                {
                    rebaseStepResult = new RebaseStepResult(RebaseStepStatus.ChangesAlreadyApplied);
                }
                else
                {
                    rebaseStepResult = new RebaseStepResult(RebaseStepStatus.Committed, rebase_commit_result.CommitId);
                }
            }
            else
            {
                rebaseStepResult = new RebaseStepResult(RebaseStepStatus.Conflicts);
            }

            return(rebaseStepResult);
        }
Exemplo n.º 9
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);
                            }
            }
        }
Exemplo n.º 10
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");

            using (ReferenceHandle branchRefPtr = RefHandleFrom(branch))
                using (ReferenceHandle upstreamRefPtr = RefHandleFrom(upstream))
                    using (ReferenceHandle ontoRefPtr = RefHandleFrom(onto))
                        return(Start(branchRefPtr, upstreamRefPtr, ontoRefPtr, committer, options));
        }
Exemplo n.º 11
0
        public virtual RebaseResult Start(Commit annotated, Commit upstream, Commit onto, Identity committer, RebaseOptions options)
        {
            Ensure.ArgumentNotNull(upstream, "upstream");

            // TODO: Rebase does not work with just references, is that a bug or design feature?
            using (var annotatedRef = ReferenceFrom(annotated))
                using (var upstreamRef = ReferenceFrom(upstream))
                    using (var ontoRef = ReferenceFrom(onto))
                        using (ReferenceHandle annotatedRefPtr = RefHandleFrom(annotatedRef?.CanonicalName))
                            using (ReferenceHandle upstreamRefPtr = RefHandleFrom(upstreamRef?.CanonicalName))
                                using (ReferenceHandle ontoRefPtr = RefHandleFrom(ontoRef?.CanonicalName))
                                    return(Start(annotatedRefPtr, upstreamRefPtr, ontoRefPtr, committer, options));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Run the current rebase step. This will handle reporting that we are about to run a rebase step,
        /// identifying and running the operation for the current step, and reporting the current step is completed.
        /// </summary>
        /// <param name="rebaseOperationHandle"></param>
        /// <param name="repository"></param>
        /// <param name="committer"></param>
        /// <param name="options"></param>
        /// <param name="stepToApplyIndex"></param>
        /// <param name="totalStepCount"/>
        /// <returns></returns>
        private static unsafe RebaseResult RunRebaseStep(RebaseHandle rebaseOperationHandle,
                                                  Repository repository,
                                                  Identity committer,
                                                  RebaseOptions options,
                                                  long stepToApplyIndex,
                                                  long totalStepCount)
        {
            RebaseStepResult rebaseStepResult = null;
            RebaseResult rebaseSequenceResult = null;

            git_rebase_operation* rebaseOp = Proxy.git_rebase_operation_byindex(rebaseOperationHandle, stepToApplyIndex);
            ObjectId idOfCommitBeingRebased = ObjectId.BuildFromPtr(&rebaseOp->id);

            RebaseStepInfo stepToApplyInfo = new RebaseStepInfo(rebaseOp->type,
                                                                repository.Lookup<Commit>(idOfCommitBeingRebased),
                                                                LaxUtf8NoCleanupMarshaler.FromNative(rebaseOp->exec));

            // Report the rebase step we are about to perform.
            if (options.RebaseStepStarting != null)
            {
                options.RebaseStepStarting(new BeforeRebaseStepInfo(stepToApplyInfo, stepToApplyIndex, totalStepCount));
            }

            // Perform the rebase step
            git_rebase_operation* rebaseOpReport = Proxy.git_rebase_next(rebaseOperationHandle);

            // Verify that the information from the native library is consistent.
            VerifyRebaseOp(rebaseOpReport, stepToApplyInfo);

            // Handle the result
            switch (stepToApplyInfo.Type)
            {
                case RebaseStepOperation.Pick:
                    rebaseStepResult = ApplyPickStep(rebaseOperationHandle, repository, committer, options, stepToApplyInfo);
                    break;
                case RebaseStepOperation.Squash:
                case RebaseStepOperation.Edit:
                // case RebaseStepOperation.Exec:
                case RebaseStepOperation.Fixup:
                case RebaseStepOperation.Reword:
                    // These operations are not yet supported by lg2.
                    throw new LibGit2SharpException("Rebase Operation Type ({0}) is not currently supported in LibGit2Sharp.",
                        stepToApplyInfo.Type);
                default:
                    throw new ArgumentException(string.Format(
                        "Unexpected Rebase Operation Type: {0}", stepToApplyInfo.Type));
            }

            // Report that we just completed the step
            if (options.RebaseStepCompleted != null &&
                (rebaseStepResult.Status == RebaseStepStatus.Committed ||
                rebaseStepResult.Status == RebaseStepStatus.ChangesAlreadyApplied))
            {
                if (rebaseStepResult.ChangesAlreadyApplied)
                {
                    options.RebaseStepCompleted(new AfterRebaseStepInfo(stepToApplyInfo, stepToApplyIndex, totalStepCount));
                }
                else
                {
                    options.RebaseStepCompleted(new AfterRebaseStepInfo(stepToApplyInfo,
                                                                        repository.Lookup<Commit>(new ObjectId(rebaseStepResult.CommitId)),
                                                                        stepToApplyIndex,
                                                                        totalStepCount));
                }
            }

            // If the result of the rebase step is something that requires us to stop
            // running the rebase sequence operations, then report the result.
            if (rebaseStepResult.Status == RebaseStepStatus.Conflicts)
            {
                rebaseSequenceResult = new RebaseResult(RebaseStatus.Conflicts,
                                                        stepToApplyIndex,
                                                        totalStepCount,
                                                        null);
            }

            return rebaseSequenceResult;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Abort the rebase operation.
        /// </summary>
        /// <param name="options">The <see cref="RebaseOptions"/> that specify the rebase behavior.</param>
        public virtual void Abort(RebaseOptions options)
        {
            options = options ?? new RebaseOptions();

            EnsureNonBareRepo();

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

                using (RebaseHandle rebase = Proxy.git_rebase_open(repository.Handle, gitRebaseOptions))
                {
                    Proxy.git_rebase_abort(rebase);
                }
            }
        }
Exemplo n.º 14
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;
                }
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Continue the current rebase.
        /// </summary>
        /// <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>
        public unsafe virtual RebaseResult Continue(Identity committer, RebaseOptions options)
        {
            Ensure.ArgumentNotNull(committer, "committer");

            options = options ?? new RebaseOptions();

            EnsureNonBareRepo();

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

                using (RebaseHandle rebase = Proxy.git_rebase_open(repository.Handle, gitRebaseOptions))
                {
                    // TODO: Should we check the pre-conditions for committing here
                    // for instance - what if we had failed on the git_rebase_finish call,
                    // do we want continue to be able to restart afterwords...
                    var rebaseCommitResult = Proxy.git_rebase_commit(rebase, null, committer);

                    // Report that we just completed the step
                    if (options.RebaseStepCompleted != null)
                    {
                        // Get information on the current step
                        long currentStepIndex = Proxy.git_rebase_operation_current(rebase);
                        long totalStepCount = Proxy.git_rebase_operation_entrycount(rebase);
                        git_rebase_operation* gitRebasestepInfo = Proxy.git_rebase_operation_byindex(rebase, currentStepIndex);

                        var stepInfo = new RebaseStepInfo(gitRebasestepInfo->type,
                                                          repository.Lookup<Commit>(ObjectId.BuildFromPtr(&gitRebasestepInfo->id)),
                                                          LaxUtf8NoCleanupMarshaler.FromNative(gitRebasestepInfo->exec));

                        if (rebaseCommitResult.WasPatchAlreadyApplied)
                        {
                            options.RebaseStepCompleted(new AfterRebaseStepInfo(stepInfo, currentStepIndex, totalStepCount));
                        }
                        else
                        {
                            options.RebaseStepCompleted(new AfterRebaseStepInfo(stepInfo,
                                                                                repository.Lookup<Commit>(new ObjectId(rebaseCommitResult.CommitId)),
                                                                                currentStepIndex,
                                                                                totalStepCount));
                        }
                    }

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