예제 #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;
        }
예제 #2
0
 internal RebaseResult(RebaseStatus status,
                       long stepNumber,
                       long totalSteps,
                       RebaseStepInfo currentStepInfo)
 {
     Status = status;
     CompletedStepCount = stepNumber;
     TotalStepCount = totalSteps;
     CurrentStepInfo = currentStepInfo;
 }
예제 #3
0
 internal RebaseResult(RebaseStatus status,
                       long stepNumber,
                       long totalSteps,
                       RebaseStepInfo currentStepInfo)
 {
     Status             = status;
     CompletedStepCount = stepNumber;
     TotalStepCount     = totalSteps;
     CurrentStepInfo    = currentStepInfo;
 }
예제 #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);
                }
            }
        }
예제 #5
0
 /// <summary>
 /// Verify that the information in a GitRebaseOperation and a RebaseStepInfo agree
 /// </summary>
 /// <param name="rebaseOpReport"></param>
 /// <param name="stepInfo"></param>
 private static void VerifyRebaseOp(GitRebaseOperation rebaseOpReport, RebaseStepInfo stepInfo)
 {
     // The step reported via querying by index and the step returned from git_rebase_next
     // should be the same
     if (rebaseOpReport == null ||
         new ObjectId(rebaseOpReport.id) != stepInfo.Commit.Id ||
         rebaseOpReport.type != stepInfo.Type)
     {
         // This is indicative of a program error - should never happen.
         throw new LibGit2SharpException("Unexpected step info reported by running rebase step.");
     }
 }
예제 #6
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);
            }
        }
예제 #7
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);
            }
        }
예제 #8
0
 internal BeforeRebaseStepInfo(RebaseStepInfo stepInfo, long stepIndex, long totalStepCount)
 {
     StepInfo = stepInfo;
     StepIndex = stepIndex;
     TotalStepCount = totalStepCount;
 }
예제 #9
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);
        }
예제 #10
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);
        }
예제 #11
0
 /// <summary>
 /// Verify that the information in a GitRebaseOperation and a RebaseStepInfo agree
 /// </summary>
 /// <param name="rebaseOpReport"></param>
 /// <param name="stepInfo"></param>
 private static unsafe void VerifyRebaseOp(git_rebase_operation* rebaseOpReport, RebaseStepInfo stepInfo)
 {
     // The step reported via querying by index and the step returned from git_rebase_next
     // should be the same
     if (rebaseOpReport == null ||
         ObjectId.BuildFromPtr(&rebaseOpReport->id) != stepInfo.Commit.Id ||
         rebaseOpReport->type != stepInfo.Type)
     {
         // This is indicative of a program error - should never happen.
         throw new LibGit2SharpException("Unexpected step info reported by running rebase step.");
     }
 }
예제 #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;
        }
예제 #13
0
 internal BeforeRebaseStepInfo(RebaseStepInfo stepInfo, long stepIndex, long totalStepCount)
 {
     StepInfo       = stepInfo;
     StepIndex      = stepIndex;
     TotalStepCount = totalStepCount;
 }
예제 #14
0
        /// <summary>
        /// Get info on the specified step
        /// </summary>
        /// <param name="stepIndex"></param>
        /// <returns></returns>
        public unsafe virtual 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;
            }
        }
예제 #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;
                }
            }
        }