예제 #1
0
 private IEnumerable <string> GetPushRefSpecs()
 {
     using (RemoteHandle remoteHandle = Proxy.git_remote_lookup(repo.Handle, remoteName, true))
     {
         return(Proxy.git_remote_get_push_refspecs(remoteHandle));
     }
 }
예제 #2
0
 internal Remote(RemoteHandle handle, Repository repository)
 {
     this.repository = repository;
     this.handle     = handle;
     refSpecs        = new RefSpecCollection(this, handle);
     repository.RegisterForCleanup(this);
 }
예제 #3
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
                    },
                    CustomHeaders = GitStrArrayManaged.BuildFrom(pushOptions.CustomHeaders),
                });
            }
        }
예제 #4
0
 /// <summary>
 /// Transform a reference to its source reference using the <see cref="Remote"/>'s default fetchspec.
 /// </summary>
 /// <param name="reference">The reference to transform.</param>
 /// <returns>The transformed reference.</returns>
 internal unsafe string FetchSpecTransformToSource(string reference)
 {
     using (RemoteHandle remoteHandle = Proxy.git_remote_lookup(repository.Handle, Name, true))
     {
         git_refspec *fetchSpecPtr = Proxy.git_remote_get_refspec(remoteHandle, 0);
         return(Proxy.git_refspec_rtransform(new IntPtr(fetchSpecPtr), reference));
     }
 }
예제 #5
0
        internal Remote RemoteForName(string name, bool shouldThrowIfNotFound = true)
        {
            Ensure.ArgumentNotNull(name, "name");

            RemoteHandle handle = Proxy.git_remote_lookup(repository.Handle, name, shouldThrowIfNotFound);

            return(handle == null ? null : new Remote(handle, this.repository));
        }
예제 #6
0
        internal RefSpecCollection(Remote remote, RemoteHandle handle)
        {
            Ensure.ArgumentNotNull(handle, "handle");

            this.remote = remote;
            this.handle = handle;

            refspecs = new Lazy <IList <RefSpec> >(() => RetrieveRefSpecs(remote, handle));
        }
예제 #7
0
        /// <summary>
        /// Creates a <see cref="Remote"/> with the specified name and for the repository at the specified location.
        /// <para>
        ///   A default fetch refspec will be added for this remote.
        /// </para>
        /// </summary>
        /// <param name="name">The name of the remote to create.</param>
        /// <param name="url">The location of the repository.</param>
        /// <returns>A new <see cref="Remote"/>.</returns>
        public virtual Remote Add(string name, string url)
        {
            Ensure.ArgumentNotNull(name, "name");
            Ensure.ArgumentNotNull(url, "url");

            RemoteHandle handle = Proxy.git_remote_create(repository.Handle, name, url);

            return(new Remote(handle, this.repository));
        }
예제 #8
0
        /// <summary>
        /// Creates a <see cref="Remote"/> with the specified name and for the repository at the specified location.
        /// </summary>
        /// <param name="name">The name of the remote to create.</param>
        /// <param name="url">The location of the repository.</param>
        /// <param name="fetchRefSpec">The refSpec to be used when fetching from this remote.</param>
        /// <returns>A new <see cref="Remote"/>.</returns>
        public virtual Remote Add(string name, string url, string fetchRefSpec)
        {
            Ensure.ArgumentNotNull(name, "name");
            Ensure.ArgumentNotNull(url, "url");
            Ensure.ArgumentNotNull(fetchRefSpec, "fetchRefSpec");

            RemoteHandle handle = Proxy.git_remote_create_with_fetchspec(repository.Handle, name, url, fetchRefSpec);

            return(new Remote(handle, this.repository));
        }
예제 #9
0
        static RemoteHandle BuildRemoteHandle(RepositoryHandle repoHandle, string url)
        {
            Debug.Assert(repoHandle != null && !repoHandle.IsNull);
            Debug.Assert(url != null);

            RemoteHandle remoteHandle = Proxy.git_remote_create_anonymous(repoHandle, url);

            Debug.Assert(remoteHandle != null && !(remoteHandle.IsNull));

            return(remoteHandle);
        }
예제 #10
0
        static unsafe IList <RefSpec> RetrieveRefSpecs(Remote remote, RemoteHandle remoteHandle)
        {
            int            count    = Proxy.git_remote_refspec_count(remoteHandle);
            List <RefSpec> refSpecs = new List <RefSpec>();

            for (int i = 0; i < count; i++)
            {
                refSpecs.Add(new RefSpec(remote, Proxy.git_remote_get_refspec(remoteHandle, i)));
            }

            return(refSpecs);
        }
예제 #11
0
파일: Fetch.cs 프로젝트: xJom/libgit2sharp
        private static RemoteHandle RemoteFromNameOrUrl(RepositoryHandle repoHandle, string remote)
        {
            RemoteHandle handle = null;

            handle = Proxy.git_remote_lookup(repoHandle, remote, false);

            // If that wasn't the name of a remote, let's use it as a url
            if (handle == null)
            {
                handle = Proxy.git_remote_create_anonymous(repoHandle, remote);
            }

            return(handle);
        }
예제 #12
0
        private IEnumerable <Reference> ListReferencesInternal(string url, CredentialsHandler credentialsProvider)
        {
            using (RemoteHandle remoteHandle = BuildRemoteHandle(repository.Handle, url))
            {
                GitRemoteCallbacks gitCallbacks = new GitRemoteCallbacks {
                    version = 1
                };

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

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