private void Update() { name = remote.Name; Url = remote.Url; PushUrl = remote.PushUrl; TagFetchMode = remote.TagFetchMode; }
/// <summary> /// Fetch from the <see cref = "Remote" />. /// </summary> /// <param name="remote">The remote to fetch</param> /// <param name="tagFetchMode">Optional parameter indicating what tags to download.</param> /// <param name="onProgress">Progress callback. Corresponds to libgit2 progress callback.</param> /// <param name="onCompletion">Completion callback. Corresponds to libgit2 completion callback.</param> /// <param name="onUpdateTips">UpdateTips callback. Corresponds to libgit2 update_tips callback.</param> /// <param name="onTransferProgress">Callback method that transfer progress will be reported through. /// Reports the client's state regarding the received and processed (bytes, objects) from the server.</param> /// <param name="credentials">Credentials to use for username/password authentication.</param> public virtual void Fetch( Remote remote, TagFetchMode tagFetchMode = TagFetchMode.Auto, ProgressHandler onProgress = null, CompletionHandler onCompletion = null, UpdateTipsHandler onUpdateTips = null, TransferProgressHandler onTransferProgress = null, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); // We need to keep a reference to the git_cred_acquire_cb callback around // so it will not be garbage collected before we are done with it. // Note that we also have a GC.KeepAlive call at the end of the method. NativeMethods.git_cred_acquire_cb credentialCallback = null; using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { var callbacks = new RemoteCallbacks(onProgress, onCompletion, onUpdateTips); GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks(); Proxy.git_remote_set_autotag(remoteHandle, tagFetchMode); if (credentials != null) { credentialCallback = (out IntPtr cred, IntPtr url, IntPtr username_from_url, uint types, IntPtr payload) => NativeMethods.git_cred_userpass_plaintext_new(out cred, credentials.Username, credentials.Password); Proxy.git_remote_set_cred_acquire_cb( remoteHandle, credentialCallback, IntPtr.Zero); } // 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. Proxy.git_remote_set_callbacks(remoteHandle, ref gitCallbacks); try { Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch); Proxy.git_remote_download(remoteHandle, onTransferProgress); Proxy.git_remote_update_tips(remoteHandle); } finally { Proxy.git_remote_disconnect(remoteHandle); } } // To be safe, make sure the credential callback is kept until // alive until at least this point. GC.KeepAlive(credentialCallback); }
private Remote(Repository repository, string name, string url, TagFetchMode tagFetchMode) { this.repository = repository; Name = name; Url = url; TagFetchMode = tagFetchMode; }
internal static Remote BuildFromPtr(RemoteSafeHandle handle, Repository repo) { string name = Proxy.git_remote_name(handle); string url = Proxy.git_remote_url(handle); TagFetchMode tagFetchMode = Proxy.git_remote_autotag(handle); var remote = new Remote(repo, name, url, tagFetchMode); return(remote); }
/// <summary> /// Fetch from the specified remote. /// </summary> /// <param name="repository">The <see cref="Repository"/> being worked with.</param> /// <param name="remoteName">The name of the <see cref="Remote"/> to fetch from.</param> /// <param name="tagFetchMode">Optional parameter indicating what tags to download.</param> /// <param name="onProgress">Progress callback. Corresponds to libgit2 progress callback.</param> /// <param name="onCompletion">Completion callback. Corresponds to libgit2 completion callback.</param> /// <param name="onUpdateTips">UpdateTips callback. Corresponds to libgit2 update_tips callback.</param> /// <param name="onTransferProgress">Callback method that transfer progress will be reported through. /// Reports the client's state regarding the received and processed (bytes, objects) from the server.</param> /// <param name="credentials">Credentials to use for username/password authentication.</param> public static void Fetch(this IRepository repository, string remoteName, TagFetchMode tagFetchMode = TagFetchMode.Auto, ProgressHandler onProgress = null, CompletionHandler onCompletion = null, UpdateTipsHandler onUpdateTips = null, TransferProgressHandler onTransferProgress = null, Credentials credentials = null) { Ensure.ArgumentNotNull(repository, "repository"); Ensure.ArgumentNotNullOrEmptyString(remoteName, "remoteName"); Remote remote = repository.Network.Remotes.RemoteForName(remoteName, true); repository.Network.Fetch(remote, tagFetchMode, onProgress, onCompletion, onUpdateTips, onTransferProgress, credentials); }
public virtual void Fetch( Remote remote, TagFetchMode? tagFetchMode = null, ProgressHandler onProgress = null, UpdateTipsHandler onUpdateTips = null, TransferProgressHandler onTransferProgress = null, Credentials credentials = null) { Fetch(remote, new FetchOptions { TagFetchMode = tagFetchMode, OnProgress = onProgress, OnUpdateTips = onUpdateTips, OnTransferProgress = onTransferProgress, Credentials = credentials }); }
public void CanSetTagFetchMode(TagFetchMode tagFetchMode) { string path = CloneBareTestRepo(); using (var repo = new Repository(path)) { const string name = "upstream"; const string url = "https://github.com/libgit2/libgit2sharp.git"; repo.Network.Remotes.Add(name, url); Remote remote = repo.Network.Remotes[name]; Assert.NotNull(remote); Remote updatedremote = repo.Network.Remotes.Update(remote, r => r.TagFetchMode = tagFetchMode); Assert.Equal(tagFetchMode, updatedremote.TagFetchMode); } }
/// <summary> /// Fetch from the <see cref="Remote"/>. /// </summary> /// <param name="remote">The remote to fetch</param> /// <param name="tagFetchMode">Optional parameter indicating what tags to download.</param> /// <param name="onProgress">Progress callback. Corresponds to libgit2 progress callback.</param> /// <param name="onUpdateTips">UpdateTips callback. Corresponds to libgit2 update_tips callback.</param> /// <param name="onTransferProgress">Callback method that transfer progress will be reported through. /// Reports the client's state regarding the received and processed (bytes, objects) from the server.</param> /// <param name="credentials">Credentials to use for username/password authentication.</param> public virtual void Fetch( Remote remote, TagFetchMode? tagFetchMode = null, ProgressHandler onProgress = null, UpdateTipsHandler onUpdateTips = null, TransferProgressHandler onTransferProgress = null, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { var callbacks = new RemoteCallbacks(onProgress, onTransferProgress, onUpdateTips, credentials); GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks(); if (tagFetchMode.HasValue) { Proxy.git_remote_set_autotag(remoteHandle, tagFetchMode.Value); } // 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. Proxy.git_remote_set_callbacks(remoteHandle, ref gitCallbacks); try { Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch); Proxy.git_remote_download(remoteHandle); Proxy.git_remote_update_tips(remoteHandle); } finally { Proxy.git_remote_disconnect(remoteHandle); } } }
public void FetchRespectsConfiguredAutoTagSetting(TagFetchMode tagFetchMode, int expectedTagCount) { string url = "http://github.com/libgit2/TestGitRepository"; using (var repo = InitIsolatedRepository()) { Remote remote = repo.Network.Remotes.Add(remoteName, url); Assert.NotNull(remote); // Update the configured autotag setting. repo.Network.Remotes.Update(remote, r => r.TagFetchMode = tagFetchMode); // Perform the actual fetch. repo.Network.Fetch(remote); // Verify the number of fetched tags. Assert.Equal(expectedTagCount, repo.Tags.Count()); } }
public Remote AddRemote(string name, string url, bool fetch, bool mirror, TagFetchMode tagFetchMode) { Verify.Argument.IsNeitherNullNorWhitespace(name, "name"); Verify.Argument.IsFalse(ContainsObjectName(name), "name", Resources.ExcObjectWithThisNameAlreadyExists.UseAsFormat("Remote")); Verify.Argument.IsNeitherNullNorWhitespace(url, "url"); Repository.Accessor.AddRemote.Invoke( new AddRemoteParameters(name, url) { Fetch = fetch, Mirror = mirror, TagFetchMode = tagFetchMode, }); var remote = new Remote(Repository, name, url, url); AddObject(remote); Repository.Refs.Remotes.Refresh(); return(remote); }
internal static extern void git_remote_set_autotag(RemoteSafeHandle remote, TagFetchMode option);