/// <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); }
/// <summary> /// Returns the next rebase step, or null if there are none, /// and the rebase operation needs to be finished. /// </summary> /// <param name="repository"></param> /// <param name="rebaseOperationHandle"></param> /// <returns></returns> private static RebaseProgress NextRebaseStep( Repository repository, RebaseHandle rebaseOperationHandle) { // stepBeingApplied indicates the step that will be applied by by git_rebase_next. // The current step does not get incremented until git_rebase_next (except on // the initial step), but we want to report the step that will be applied. long stepToApplyIndex = Proxy.git_rebase_operation_current(rebaseOperationHandle); stepToApplyIndex++; long totalStepCount = Proxy.git_rebase_operation_entrycount(rebaseOperationHandle); if (stepToApplyIndex == totalStepCount) { stepToApplyIndex = -1; } RebaseProgress progress = new RebaseProgress() { current = stepToApplyIndex, total = totalStepCount, }; return(progress); }
/// <summary> /// Returns the next rebase step, or null if there are none, /// and the rebase operation needs to be finished. /// </summary> /// <param name="repository"></param> /// <param name="rebaseOperationHandle"></param> /// <returns></returns> private static RebaseProgress NextRebaseStep( Repository repository, RebaseHandle rebaseOperationHandle) { // stepBeingApplied indicates the step that will be applied by by git_rebase_next. // The current step does not get incremented until git_rebase_next (except on // the initial step), but we want to report the step that will be applied. long stepToApplyIndex = Proxy.git_rebase_operation_current(rebaseOperationHandle); stepToApplyIndex++; long totalStepCount = Proxy.git_rebase_operation_entrycount(rebaseOperationHandle); if (stepToApplyIndex == totalStepCount) { stepToApplyIndex = -1; } RebaseProgress progress = new RebaseProgress() { current = stepToApplyIndex, total = totalStepCount, }; return progress; }