Esempio n. 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(string.Format(
                                                    "A {0} operation is already in progress.", this.repository.Info.CurrentOperation));
            }

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

            Func <ReferenceSafeHandle, GitAnnotatedCommitHandle> AnnotatedCommitHandleFromRefHandle =
                (ReferenceSafeHandle refHandle) =>
            {
                return((refHandle == null) ?
                       new GitAnnotatedCommitHandle() :
                       Proxy.git_annotated_commit_from_ref(this.repository.Handle, refHandle));
            };

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

                using (ReferenceSafeHandle branchRefPtr = RefHandleFromBranch(branch))
                    using (ReferenceSafeHandle upstreamRefPtr = RefHandleFromBranch(upstream))
                        using (ReferenceSafeHandle ontoRefPtr = RefHandleFromBranch(onto))
                            using (GitAnnotatedCommitHandle annotatedBranchCommitHandle = AnnotatedCommitHandleFromRefHandle(branchRefPtr))
                                using (GitAnnotatedCommitHandle upstreamRefAnnotatedCommitHandle = AnnotatedCommitHandleFromRefHandle(upstreamRefPtr))
                                    using (GitAnnotatedCommitHandle ontoRefAnnotatedCommitHandle = AnnotatedCommitHandleFromRefHandle(ontoRefPtr))
                                        using (RebaseSafeHandle rebaseOperationHandle = Proxy.git_rebase_init(this.repository.Handle,
                                                                                                              annotatedBranchCommitHandle,
                                                                                                              upstreamRefAnnotatedCommitHandle,
                                                                                                              ontoRefAnnotatedCommitHandle,
                                                                                                              gitRebaseOptions))
                                        {
                                            RebaseResult rebaseResult = RebaseOperationImpl.Run(rebaseOperationHandle,
                                                                                                this.repository,
                                                                                                committer,
                                                                                                options);
                                            return(rebaseResult);
                                        }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public virtual long GetTotalStepCount()
        {
            GitRebaseOptions gitRebaseOptions = new GitRebaseOptions()
            {
                version = 1,
            };

            using (RebaseHandle rebaseHandle = Proxy.git_rebase_open(repository.Handle, gitRebaseOptions))
            {
                return(Proxy.git_rebase_operation_entrycount(rebaseHandle));
            }
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public virtual long GetCurrentStepIndex()
        {
            GitRebaseOptions gitRebaseOptions = new GitRebaseOptions()
            {
                version = 1,
            };

            using (RebaseHandle rebaseHandle = Proxy.git_rebase_open(repository.Handle, gitRebaseOptions))
            {
                return(Proxy.git_rebase_operation_current(rebaseHandle));
            }
        }
Esempio 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);
                }
            }
        }
Esempio n. 5
0
        private static RebaseResult CompleteRebase(RebaseSafeHandle rebaseOperationHandle, Identity committer, RebaseResult rebaseResult)
        {
            long             totalStepCount   = Proxy.git_rebase_operation_entrycount(rebaseOperationHandle);
            GitRebaseOptions gitRebaseOptions = new GitRebaseOptions()
            {
                version = 1,
            };

            // Rebase is completed!
            Proxy.git_rebase_finish(rebaseOperationHandle, committer);
            rebaseResult = new RebaseResult(RebaseStatus.Complete,
                                            totalStepCount,
                                            totalStepCount,
                                            null);
            return(rebaseResult);
        }
Esempio n. 6
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);
                }
            }
        }
Esempio n. 7
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);
                            }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Get info on the specified step
        /// </summary>
        /// <param name="stepIndex"></param>
        /// <returns></returns>
        public virtual unsafe RebaseStepInfo GetStepInfo(long stepIndex)
        {
            if (repository.Info.CurrentOperation != LibGit2Sharp.CurrentOperation.RebaseMerge)
            {
                return(null);
            }

            GitRebaseOptions gitRebaseOptions = new GitRebaseOptions()
            {
                version = 1,
            };

            using (RebaseHandle rebaseHandle = Proxy.git_rebase_open(repository.Handle, gitRebaseOptions))
            {
                git_rebase_operation *gitRebasestepInfo = Proxy.git_rebase_operation_byindex(rebaseHandle, stepIndex);
                var stepInfo = new RebaseStepInfo(gitRebasestepInfo->type,
                                                  repository.Lookup <Commit>(ObjectId.BuildFromPtr(&gitRebasestepInfo->id)),
                                                  LaxUtf8Marshaler.FromNative(gitRebasestepInfo->exec));
                return(stepInfo);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// The info on the current step.
        /// </summary>
        public virtual RebaseStepInfo GetCurrentStepInfo()
        {
            if (repository.Info.CurrentOperation != LibGit2Sharp.CurrentOperation.RebaseMerge)
            {
                return(null);
            }

            GitRebaseOptions gitRebaseOptions = new GitRebaseOptions()
            {
                version = 1,
            };

            using (RebaseSafeHandle rebaseHandle = Proxy.git_rebase_open(repository.Handle, gitRebaseOptions))
            {
                long currentStepIndex = Proxy.git_rebase_operation_current(rebaseHandle);
                GitRebaseOperation gitRebasestepInfo = Proxy.git_rebase_operation_byindex(rebaseHandle, currentStepIndex);
                var stepInfo = new RebaseStepInfo(gitRebasestepInfo.type,
                                                  repository.Lookup <Commit>(new ObjectId(gitRebasestepInfo.id)),
                                                  LaxUtf8Marshaler.FromNative(gitRebasestepInfo.exec));
                return(stepInfo);
            }
        }