/// <summary> /// Update specified submodule. /// <para> /// This will: /// 1) Optionally initialize the if it not already initialzed, /// 2) clone the sub repository if it has not already been cloned, and /// 3) checkout the commit ID for the submodule in the sub repository. /// </para> /// </summary> /// <param name="name">The name of the submodule to update.</param> /// <param name="options">Options controlling submodule udpate behavior and callbacks.</param> public virtual void Update(string name, SubmoduleUpdateOptions options) { options = options ?? new SubmoduleUpdateOptions(); using (var handle = Proxy.git_submodule_lookup(repo.Handle, name)) { if (handle == null) { throw new NotFoundException("Submodule lookup failed for '{0}'.", name); } using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options)) { var gitCheckoutOptions = checkoutOptionsWrapper.Options; var remoteCallbacks = new RemoteCallbacks(options); var gitRemoteCallbacks = remoteCallbacks.GenerateCallbacks(); var gitSubmoduleUpdateOpts = new GitSubmoduleOptions { Version = 1, CheckoutOptions = gitCheckoutOptions, FetchOptions = new GitFetchOptions { RemoteCallbacks = gitRemoteCallbacks }, CloneCheckoutStrategy = CheckoutStrategy.GIT_CHECKOUT_SAFE }; Proxy.git_submodule_update(handle, options.Init, ref gitSubmoduleUpdateOpts); } } }
/// <summary> /// Pops a single stashed state from the stash list /// </summary> /// <param name="index">the index of the stash to remove (0 being the most recent one).</param> /// <param name="options">the options to use for checking out the stash.</param> public virtual StashApplyStatus Pop(int index, StashApplyOptions options) { if (index < 0) { throw new ArgumentException("The passed index must be a positive integer.", "index"); } if (options == null) { options = new StashApplyOptions(); } using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options.CheckoutOptions ?? new CheckoutOptions())) { var opts = new GitStashApplyOpts { CheckoutOptions = checkoutOptionsWrapper.Options, Flags = options.ApplyModifiers, }; if (options.ProgressHandler != null) { opts.ApplyProgressCallback = (progress, payload) => options.ProgressHandler(progress) ? 0 : -1; } return(Proxy.git_stash_pop(repo.Handle, index, opts)); } }
/// <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); } } }
/// <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); } } }
/// <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); } } }
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); } } }