Пример #1
0
        /// <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 GitSubmoduleUpdateOptions
                    {
                        Version         = 1,
                        CheckoutOptions = gitCheckoutOptions,
                        FetchOptions    = new GitFetchOptions {
                            ProxyOptions = new GitProxyOptions {
                                Version = 1
                            }, RemoteCallbacks = gitRemoteCallbacks
                        },
                        CloneCheckoutStrategy = CheckoutStrategy.GIT_CHECKOUT_SAFE
                    };

                    Proxy.git_submodule_update(handle, options.Init, ref gitSubmoduleUpdateOpts);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Push specified references to the <see cref="Remote"/>.
        /// </summary>
        /// <param name="remote">The <see cref="Remote"/> to push to.</param>
        /// <param name="pushRefSpecs">The pushRefSpecs to push.</param>
        /// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
        public virtual void Push(Remote remote, IEnumerable <string> pushRefSpecs, PushOptions pushOptions)
        {
            Ensure.ArgumentNotNull(remote, "remote");
            Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs");

            // Return early if there is nothing to push.
            if (!pushRefSpecs.Any())
            {
                return;
            }

            if (pushOptions == null)
            {
                pushOptions = new PushOptions();
            }

            // Load the remote.
            using (RemoteHandle remoteHandle = Proxy.git_remote_lookup(repository.Handle, remote.Name, true))
            {
                var callbacks = new RemoteCallbacks(pushOptions);
                GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks();

                Proxy.git_remote_push(remoteHandle,
                                      pushRefSpecs,
                                      new GitPushOptions()
                {
                    PackbuilderDegreeOfParallelism = pushOptions.PackbuilderDegreeOfParallelism,
                    RemoteCallbacks = gitCallbacks,
                    ProxyOptions    = new GitProxyOptions {
                        Version = 1
                    },
                });
            }
        }
Пример #3
0
        /// <summary>
        /// Perform a fetch
        /// </summary>
        /// <param name="repository">The repository in which to fetch.</param>
        /// <param name="remote">The remote to fetch from. Either as a remote name or a URL</param>
        /// <param name="options">Fetch options.</param>
        /// <param name="logMessage">Log message for any ref updates.</param>
        /// <param name="refspecs">List of refspecs to apply as active.</param>
        public static void Fetch(Repository repository, string remote, IEnumerable <string> refspecs, FetchOptions options, string logMessage)
        {
            Ensure.ArgumentNotNull(remote, "remote");

            options = options ?? new FetchOptions();
            using (var remoteHandle = RemoteFromNameOrUrl(repository.Handle, remote))
                using (var fetchOptionsWrapper = new GitFetchOptionsWrapper())
                {
                    var callbacks = new RemoteCallbacks(options);
                    GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks();

                    // It is OK to pass the reference to the GitCallbacks directly here because libgit2 makes a copy of
                    // the data in the git_remote_callbacks structure. If, in the future, libgit2 changes its implementation
                    // to store a reference to the git_remote_callbacks structure this would introduce a subtle bug
                    // where the managed layer could move the git_remote_callbacks to a different location in memory,
                    // but libgit2 would still reference the old address.
                    //
                    // Also, if GitRemoteCallbacks were a class instead of a struct, we would need to guard against
                    // GC occuring in between setting the remote callbacks and actual usage in one of the functions afterwords.
                    var fetchOptions = fetchOptionsWrapper.Options;
                    fetchOptions.RemoteCallbacks = gitCallbacks;
                    fetchOptions.download_tags   = Proxy.git_remote_autotag(remoteHandle);

                    if (options.TagFetchMode.HasValue)
                    {
                        fetchOptions.download_tags = options.TagFetchMode.Value;
                    }

                    if (options.Prune.HasValue)
                    {
                        fetchOptions.Prune = options.Prune.Value ? FetchPruneStrategy.Prune : FetchPruneStrategy.NoPrune;
                    }
                    else
                    {
                        fetchOptions.Prune = FetchPruneStrategy.FromConfigurationOrDefault;
                    }

                    if (options.CustomHeaders != null && options.CustomHeaders.Length > 0)
                    {
                        fetchOptions.CustomHeaders = GitStrArrayManaged.BuildFrom(options.CustomHeaders);
                    }

                    fetchOptions.ProxyOptions = new GitProxyOptions {
                        Version = 1
                    };

                    Proxy.git_remote_fetch(remoteHandle, refspecs, fetchOptions, logMessage);
                }
        }
Пример #4
0
        private IEnumerable <Reference> ListReferencesInternal(string url, CredentialsHandler credentialsProvider)
        {
            using (RemoteHandle remoteHandle = BuildRemoteHandle(repository.Handle, url))
            {
                GitRemoteCallbacks gitCallbacks = new GitRemoteCallbacks {
                    version = 1
                };
                GitProxyOptions proxyOptions = new GitProxyOptions {
                    Version = 1
                };

                if (credentialsProvider != null)
                {
                    var callbacks = new RemoteCallbacks(credentialsProvider);
                    gitCallbacks = callbacks.GenerateCallbacks();
                }

                Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch, ref gitCallbacks, ref proxyOptions);
                return(Proxy.git_remote_ls(repository, remoteHandle));
            }
        }