/// <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); }
/// <summary> /// Push specified reference to the <see cref="Remote"/>. /// </summary> /// <param name="network">The <see cref="Network"/> being worked with.</param> /// <param name="remote">The <see cref = "Remote" /> to push to.</param> /// <param name="pushRefSpec">The pushRefSpec to push.</param> /// <param name="credentials">Credentials to use for user/pass authentication</param> /// <returns>Results of the push operation.</returns> public static PushResult Push(this Network network, Remote remote, string pushRefSpec, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNullOrEmptyString(pushRefSpec, "pushRefSpec"); return network.Push(remote, new string[] { pushRefSpec }, credentials); }
/// <summary> /// List references in a <see cref = "Remote" /> repository. /// </summary> /// <param name="remote">The <see cref = "Remote" /> to list from.</param> /// <returns>The references in the <see cref = "Remote" /> repository.</returns> public virtual IEnumerable<DirectReference> ListReferences(Remote remote) { Ensure.ArgumentNotNull(remote, "remote"); List<DirectReference> directReferences = new List<DirectReference>(); using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch); NativeMethods.git_headlist_cb cb = (ref GitRemoteHead remoteHead, IntPtr payload) => { // The name pointer should never be null - if it is, // this indicates a bug somewhere (libgit2, server, etc). if (remoteHead.NamePtr == IntPtr.Zero) { Proxy.giterr_set_str(GitErrorCategory.Invalid, "Not expecting null value for reference name."); return -1; } ObjectId oid = remoteHead.Oid; string name = Utf8Marshaler.FromNative(remoteHead.NamePtr); directReferences.Add(new DirectReference(name, this.repository, oid)); return 0; }; Proxy.git_remote_ls(remoteHandle, cb); } return directReferences; }
private Remote RemoteForName(string name) { var remote = new Remote(); RemoteSafeHandle handle; int res = NativeMethods.git_remote_get(out handle, repository.Config.Handle, name); if (res == (int)GitErrorCode.GIT_ENOTFOUND) { return null; } Ensure.Success(res); using (handle) { var ptr = NativeMethods.git_remote_name(handle); remote.Name = ptr.MarshallAsString(); ptr = NativeMethods.git_remote_url(handle); remote.Url = ptr.MarshallAsString(); } return remote; }
private DirectReference GetPullRequestReference(AuthenticationInfo auth, LibGit2Sharp.Remote remote, string headTipSha) { var network = RepositoryInstance.Network; var credentialsProvider = GetCredentialsProvider(auth); var remoteTips = (credentialsProvider != null ? network.ListReferences(remote, credentialsProvider) : network.ListReferences(remote)) .Select(r => r.ResolveToDirectReference()).ToList(); this.log.Info($"Remote Refs:{System.Environment.NewLine}" + string.Join(System.Environment.NewLine, remoteTips.Select(r => r.CanonicalName))); var refs = remoteTips.Where(r => r.TargetIdentifier == headTipSha).ToList(); switch (refs.Count) { case 0: { var message = $"Couldn't find any remote tips from remote '{remote.Url}' pointing at the commit '{headTipSha}'."; throw new WarningException(message); } case > 1: { var names = string.Join(", ", refs.Select(r => r.CanonicalName)); var message = $"Found more than one remote tip from remote '{remote.Url}' pointing at the commit '{headTipSha}'. Unable to determine which one to use ({names})."; throw new WarningException(message); } } return(refs.First()); }
internal RemoteUpdater(Repository repo, Remote remote) { Ensure.ArgumentNotNull(repo, "repo"); Ensure.ArgumentNotNull(remote, "remote"); this.repo = repo; this.remote = remote; }
/// <summary> /// Fetch from the <see cref="Remote"/>. /// </summary> /// <param name="remote">The remote to fetch</param> /// <param name="options"><see cref="FetchOptions"/> controlling fetch behavior</param> public virtual void Fetch(Remote remote, FetchOptions options = null) { Ensure.ArgumentNotNull(remote, "remote"); using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { DoFetch(remoteHandle, options); } }
/// <summary> /// Fetch from the <see cref="Remote"/>. /// </summary> /// <param name="remote">The remote to fetch</param> /// <param name="options"><see cref="FetchOptions"/> controlling fetch behavior</param> /// <param name="signature">Identity for use when updating the reflog.</param> /// <param name="logMessage">Message to use when updating the reflog.</param> public virtual void Fetch(Remote remote, FetchOptions options = null, Signature signature = null, string logMessage = null) { Ensure.ArgumentNotNull(remote, "remote"); using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { DoFetch(remoteHandle, options, signature.OrDefault(repository.Config), logMessage); } }
private void AddMissingRefSpecs(LibGit2Sharp.Remote remote) { if (remote.FetchRefSpecs.Any(r => r.Source == "refs/heads/*")) { return; } var allBranchesFetchRefSpec = $"+refs/heads/*:refs/remotes/{remote.Name}/*"; log.Info($"Adding refspec: {allBranchesFetchRefSpec}"); repositoryInstance.Network.Remotes.Update(remote.Name, r => r.FetchRefSpecs.Add(allBranchesFetchRefSpec)); }
static void AddMissingRefSpecs(Repository repo, Remote remote) { if (remote.FetchRefSpecs.Any(r => r.Source == "refs/heads/*")) return; var allBranchesFetchRefSpec = string.Format("+refs/heads/*:refs/remotes/{0}/*", remote.Name); Logger.WriteInfo(string.Format("Adding refspec: {0}", allBranchesFetchRefSpec)); repo.Network.Remotes.Update(remote, r => r.FetchRefSpecs.Add(allBranchesFetchRefSpec)); }
public void CreateRemoteForMasterBranch() { using LibGit2Sharp.Repository repository = new(Module.WorkingDir); repository.Network.Remotes.Add("origin", "http://useless.url"); Remote remote = repository.Network.Remotes["origin"]; var masterBranch = repository.Branches["master"]; repository.Branches.Update(masterBranch, b => b.Remote = remote.Name, b => b.UpstreamBranch = masterBranch.CanonicalName); }
public static void RemoteFetch( Remote remote, Credentials creds, Console console ) { try { remote.Fetch( TagFetchMode.Auto, OnProgress, OnCompletion, OnUpdateTips, OnTransferProgress, credentials: creds ); } catch ( System.Exception e ) { Debug.Log( e ); } }
/// <summary> /// Push the objectish to the destination reference on the <see cref = "Remote" />. /// </summary> /// <param name="network">The <see cref="Network"/> being worked with.</param> /// <param name="remote">The <see cref = "Remote" /> to push to.</param> /// <param name="objectish">The source objectish to push.</param> /// <param name="destinationSpec">The reference to update on the remote.</param> /// <param name="credentials">Credentials to use for user/pass authentication</param> /// <returns>Results of the push operation.</returns> public static PushResult Push( this Network network, Remote remote, string objectish, string destinationSpec, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(objectish, "objectish"); Ensure.ArgumentNotNullOrEmptyString(destinationSpec, "destinationSpec"); return network.Push(remote, string.Format(CultureInfo.InvariantCulture, "{0}:{1}", objectish, destinationSpec), credentials); }
public EditRemoteDialog (Remote remote) { this.Build (); this.UseNativeContextMenus (); if (remote != null) { entryName.Text = remote.Name; entryUrl.Text = remote.Url ?? ""; entryPushUrl.Text = remote.PushUrl ?? ""; } checkImportTags.Visible = remote == null; UpdateButtons (); }
/// <summary> /// Push specified references to the <see cref="Remote"/>. /// </summary> /// <param name="network">The <see cref="Network"/> being worked with.</param> /// <param name="remote">The <see cref="Remote"/> to push to.</param> /// <param name="pushRefSpecs">The pushRefSpecs to push.</param> /// <param name="credentials">Credentials to use for user/pass authentication</param> /// <returns>Results of the push operation.</returns> public static PushResult Push(this Network network, Remote remote, IEnumerable<string> pushRefSpecs, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs"); List<PushStatusError> failedRemoteUpdates = new List<PushStatusError>(); network.Push( remote, pushRefSpecs, failedRemoteUpdates.Add, credentials); return new PushResult(failedRemoteUpdates); }
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 }); }
private void OnEnable() { configManager = new ConfigManager( this ); try { repo = new Repository( configManager.explicitPathToRepository ?? Directory.GetCurrentDirectory() ); branch = repo.Head; remote = repo.Network.Remotes[ "origin" ]; } catch { SetupWindow.cns = this; EditorWindow.GetWindow( typeof( SetupWindow ), false, "UniTEAM Setup" ); return; } changeWindow( WindowSet.overview ); isConsoleReady = true; }
/// <summary> /// List references in a <see cref="Remote"/> repository. /// <para> /// When the remote tips are ahead of the local ones, the retrieved /// <see cref="DirectReference"/>s may point to non existing /// <see cref="GitObject"/>s in the local repository. In that /// case, <see cref="DirectReference.Target"/> will return <c>null</c>. /// </para> /// </summary> /// <param name="remote">The <see cref="Remote"/> to list from.</param> /// <param name="credentialsProvider">The optional <see cref="Func{Credentials}"/> used to connect to remote repository.</param> /// <returns>The references in the <see cref="Remote"/> repository.</returns> public virtual IEnumerable<DirectReference> ListReferences(Remote remote, CredentialsHandler credentialsProvider = null) { Ensure.ArgumentNotNull(remote, "remote"); using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { if (credentialsProvider != null) { var callbacks = new RemoteCallbacks(null, null, null, credentialsProvider); GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks(); Proxy.git_remote_set_callbacks(remoteHandle, ref gitCallbacks); } Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch); return Proxy.git_remote_ls(repository, remoteHandle); } }
/// <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 virtual void Fetch(Remote remote) { Commands.Fetch(repository, remote.Name, new string[0], null, null); }
static IEnumerable<DirectReference> GetRemoteTipsForAnonymousUser(Repository repo, Remote remote) { return repo.Network.ListReferences(remote).Select(r => r.ResolveToDirectReference()); }
public static void Fetch(AuthenticationInfo authentication, Remote remote, Repository repo) { Log.Info(string.Format("Fetching from remote '{0}' using the following refspecs: {1}.", remote.Name, string.Join(", ", remote.FetchRefSpecs.Select(r => r.Specification)))); Commands.Fetch(repo, remote.Name, new string[0], authentication.ToFetchOptions(), null); }
internal unsafe RefSpec(Remote remote, git_refspec *handle) { this.remote = remote; this.handle = new IntPtr(handle); }
public virtual void Fetch(Remote remote, FetchOptions options) { Commands.Fetch(repository, remote.Name, new string[0], options, null); }
/// <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 }, }); } }
/// <summary> /// Fetch from the <see cref="Remote"/>. /// </summary> /// <param name="remote">The remote to fetch</param> /// <param name="logMessage">Message to use when updating the reflog.</param> public virtual void Fetch(Remote remote, string logMessage) { Fetch(remote, (FetchOptions)null, logMessage); }
/// <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> /// <param name="signature">Identity for use when updating the reflog.</param> /// <param name="logMessage">Message to use when updating the reflog.</param> public virtual void Push( Remote remote, IEnumerable <string> pushRefSpecs, PushOptions pushOptions = null, Signature signature = null, string logMessage = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs"); // The following local variables are protected from garbage collection // by a GC.KeepAlive call at the end of the method. Otherwise, // random crashes during push progress reporting could occur. PushTransferCallbacks pushTransferCallbacks; PackbuilderCallbacks packBuilderCallbacks; NativeMethods.git_push_transfer_progress pushProgress; NativeMethods.git_packbuilder_progress packBuilderProgress; // Return early if there is nothing to push. if (!pushRefSpecs.Any()) { return; } if (pushOptions == null) { pushOptions = new PushOptions(); } PushCallbacks pushStatusUpdates = new PushCallbacks(pushOptions.OnPushStatusError); // Load the remote. using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { var callbacks = new RemoteCallbacks(pushOptions.CredentialsProvider); GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks(); Proxy.git_remote_set_callbacks(remoteHandle, ref gitCallbacks); try { Proxy.git_remote_connect(remoteHandle, GitDirection.Push); // Perform the actual push. using (PushSafeHandle pushHandle = Proxy.git_push_new(remoteHandle)) { pushTransferCallbacks = new PushTransferCallbacks(pushOptions.OnPushTransferProgress); packBuilderCallbacks = new PackbuilderCallbacks(pushOptions.OnPackBuilderProgress); pushProgress = pushTransferCallbacks.GenerateCallback(); packBuilderProgress = packBuilderCallbacks.GenerateCallback(); Proxy.git_push_set_callbacks(pushHandle, pushProgress, packBuilderProgress); // Set push options. Proxy.git_push_set_options(pushHandle, new GitPushOptions() { PackbuilderDegreeOfParallelism = pushOptions.PackbuilderDegreeOfParallelism }); // Add refspecs. foreach (string pushRefSpec in pushRefSpecs) { Proxy.git_push_add_refspec(pushHandle, pushRefSpec); } Proxy.git_push_finish(pushHandle); if (!Proxy.git_push_unpack_ok(pushHandle)) { throw new LibGit2SharpException("Push failed - remote did not successfully unpack."); } Proxy.git_push_status_foreach(pushHandle, pushStatusUpdates.Callback); Proxy.git_push_update_tips(pushHandle, signature.OrDefault(repository.Config), logMessage); } } finally { Proxy.git_remote_disconnect(remoteHandle); } } GC.KeepAlive(pushProgress); GC.KeepAlive(packBuilderProgress); GC.KeepAlive(pushTransferCallbacks); GC.KeepAlive(packBuilderCallbacks); }
/// <summary> /// List references in a <see cref="Remote"/> repository. /// <para> /// When the remote tips are ahead of the local ones, the retrieved /// <see cref="DirectReference"/>s may point to non existing /// <see cref="GitObject"/>s in the local repository. In that /// case, <see cref="DirectReference.Target"/> will return <c>null</c>. /// </para> /// </summary> /// <param name="remote">The <see cref="Remote"/> to list from.</param> /// <returns>The references in the <see cref="Remote"/> repository.</returns> public virtual IEnumerable <Reference> ListReferences(Remote remote) { Ensure.ArgumentNotNull(remote, "remote"); return(ListReferencesInternal(remote.Url, null)); }
/// <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> public virtual void Push(Remote remote, IEnumerable <string> pushRefSpecs) { Push(remote, pushRefSpecs, null); }
/// <summary> /// Push specified reference to the <see cref="Remote"/>. /// </summary> /// <param name="remote">The <see cref="Remote"/> to push to.</param> /// <param name="pushRefSpec">The pushRefSpec to push.</param> public virtual void Push(Remote remote, string pushRefSpec) { Ensure.ArgumentNotNullOrEmptyString(pushRefSpec, "pushRefSpec"); Push(remote, new[] { pushRefSpec }); }
public void UpdateRemote(string oldName, string url) { LibGit2Sharp.Remote r = Repository.Network.Remotes[oldName]; Repository.Network.Remotes.Update(oldName, rem => rem.Url = url); }
/// <summary> /// Fetch from the <see cref="Remote"/>, using custom refspecs. /// </summary> /// <param name="remote">The remote to fetch</param> /// <param name="refspecs">Refspecs to use, replacing the remote's fetch refspecs</param> /// <param name="options"><see cref="FetchOptions"/> controlling fetch behavior</param> public virtual void Fetch(Remote remote, IEnumerable <string> refspecs, FetchOptions options) { Fetch(remote, refspecs, options, null); }
public void FetchWithoutConflict(string remoteUrl, string branchName) { var tracer = _tracerFactory.GetTracer(); try { using (var repo = new LibGit2Sharp.Repository(RepositoryPath)) { var trackedBranchName = string.Format("{0}/{1}", _remoteAlias, branchName); var refSpec = string.Format("+refs/heads/{0}:refs/remotes/{1}", branchName, trackedBranchName); LibGit2Sharp.Remote remote = null; using (tracer.Step("LibGit2SharpRepository Add Remote")) { // only add if matching remote does not exist // to address strange LibGit2SharpRepository remove and add remote issue (remote already exists!) remote = repo.Network.Remotes[_remoteAlias]; if (remote != null && string.Equals(remote.Url, remoteUrl, StringComparison.OrdinalIgnoreCase) && remote.FetchRefSpecs.Any(rf => string.Equals(rf.Specification, refSpec, StringComparison.OrdinalIgnoreCase))) { tracer.Trace("Git remote exists"); } else { // Remove it if it already exists (does not throw if it doesn't) repo.Network.Remotes.Remove(_remoteAlias); // Configure the remote remote = repo.Network.Remotes.Add(_remoteAlias, remoteUrl, refSpec); tracer.Trace("Git remote added"); } } using (tracer.Step("LibGit2SharpRepository Fetch")) { // This will only retrieve the "master" repo.Network.Fetch(remote); } using (tracer.Step("LibGit2SharpRepository Update")) { // Are we fetching a tag? if (branchName.Trim().StartsWith("refs/tags/", StringComparison.OrdinalIgnoreCase)) { var trackedTag = repo.Tags[branchName]; if (trackedTag == null) { throw new BranchNotFoundException(branchName, null); } // Update the raw ref to point to the tag UpdateRawRef(branchName, branchName); // Now checkout out the tag, which points to the right place Update(branchName); } else { // Optionally set up the branch tracking configuration var trackedBranch = repo.Branches[trackedBranchName]; if (trackedBranch == null) { throw new BranchNotFoundException(branchName, null); } var branch = repo.Branches[branchName] ?? repo.CreateBranch(branchName, trackedBranch.Tip); repo.Branches.Update(branch, b => b.TrackedBranch = trackedBranch.CanonicalName); // Update the raw ref to point the head of branchName to the latest fetched branch UpdateRawRef(string.Format("refs/heads/{0}", branchName), trackedBranchName); // Now checkout out our branch, which points to the right place Update(branchName); } } } } catch (LibGit2SharpException exception) { // LibGit2Sharp doesn't support SSH yet. Use GitExeRepository // LibGit2Sharp only supports smart Http protocol if (exception.Message.Equals("Unsupported URL protocol") || exception.Message.Equals("Received unexpected content-type")) { tracer.TraceWarning("LibGit2SharpRepository fallback to git.exe due to {0}", exception.Message); _legacyGitExeRepository.FetchWithoutConflict(remoteUrl, branchName); } else { throw; } } }
/// <summary> /// Fetch from the <see cref="Remote"/>. /// </summary> /// <param name="remote">The remote to fetch</param> public virtual void Fetch(Remote remote) { Fetch(remote, (FetchOptions)null, null); }
public virtual void Fetch(Remote remote, string logMessage) { Commands.Fetch(repository, remote.Name, new string[0], null, logMessage); }
/// <summary> /// Push the objectish to the destination reference on the <see cref="Remote"/>. /// </summary> /// <param name="remote">The <see cref="Remote"/> to push to.</param> /// <param name="objectish">The source objectish to push.</param> /// <param name="destinationSpec">The reference to update on the remote.</param> /// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param> /// <param name="signature">Identity for use when updating the reflog.</param> /// <param name="logMessage">Message to use when updating the reflog.</param> public virtual void Push( Remote remote, string objectish, string destinationSpec, PushOptions pushOptions = null, Signature signature = null, string logMessage = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(objectish, "objectish"); Ensure.ArgumentNotNullOrEmptyString(destinationSpec, destinationSpec); Push(remote, string.Format(CultureInfo.InvariantCulture, "{0}:{1}", objectish, destinationSpec), pushOptions, signature, logMessage); }
/// <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> /// <param name="signature">Identity for use when updating the reflog.</param> /// <param name="logMessage">Message to use when updating the reflog.</param> public virtual void Push( Remote remote, IEnumerable<string> pushRefSpecs, PushOptions pushOptions = null, Signature signature = null, string logMessage = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs"); // The following local variables are protected from garbage collection // by a GC.KeepAlive call at the end of the method. Otherwise, // random crashes during push progress reporting could occur. PushTransferCallbacks pushTransferCallbacks; PackbuilderCallbacks packBuilderCallbacks; NativeMethods.git_push_transfer_progress pushProgress; NativeMethods.git_packbuilder_progress packBuilderProgress; // Return early if there is nothing to push. if (!pushRefSpecs.Any()) { return; } if (pushOptions == null) { pushOptions = new PushOptions(); } PushCallbacks pushStatusUpdates = new PushCallbacks(pushOptions.OnPushStatusError); // Load the remote. using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { var callbacks = new RemoteCallbacks(null, null, null, pushOptions.Credentials); GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks(); Proxy.git_remote_set_callbacks(remoteHandle, ref gitCallbacks); try { Proxy.git_remote_connect(remoteHandle, GitDirection.Push); // Perform the actual push. using (PushSafeHandle pushHandle = Proxy.git_push_new(remoteHandle)) { pushTransferCallbacks = new PushTransferCallbacks(pushOptions.OnPushTransferProgress); packBuilderCallbacks = new PackbuilderCallbacks(pushOptions.OnPackBuilderProgress); pushProgress = pushTransferCallbacks.GenerateCallback(); packBuilderProgress = packBuilderCallbacks.GenerateCallback(); Proxy.git_push_set_callbacks(pushHandle, pushProgress, packBuilderProgress); // Set push options. Proxy.git_push_set_options(pushHandle, new GitPushOptions() { PackbuilderDegreeOfParallelism = pushOptions.PackbuilderDegreeOfParallelism }); // Add refspecs. foreach (string pushRefSpec in pushRefSpecs) { Proxy.git_push_add_refspec(pushHandle, pushRefSpec); } Proxy.git_push_finish(pushHandle); if (!Proxy.git_push_unpack_ok(pushHandle)) { throw new LibGit2SharpException("Push failed - remote did not successfully unpack."); } Proxy.git_push_status_foreach(pushHandle, pushStatusUpdates.Callback); Proxy.git_push_update_tips(pushHandle, signature.OrDefault(repository.Config), logMessage); } } finally { Proxy.git_remote_disconnect(remoteHandle); } } GC.KeepAlive(pushProgress); GC.KeepAlive(packBuilderProgress); GC.KeepAlive(pushTransferCallbacks); GC.KeepAlive(packBuilderCallbacks); }
/// <summary> /// Fetch from the <see cref="Remote"/>, using custom refspecs. /// </summary> /// <param name="remote">The remote to fetch</param> /// <param name="refspecs">Refspecs to use, replacing the remote's fetch refspecs</param> /// <param name="logMessage">Message to use when updating the reflog.</param> public virtual void Fetch(Remote remote, IEnumerable <string> refspecs, string logMessage) { Fetch(remote, refspecs, null, logMessage); }
/// <summary> /// Push specified reference to the <see cref="Remote"/>. /// </summary> /// <param name="remote">The <see cref="Remote"/> to push to.</param> /// <param name="pushRefSpec">The pushRefSpec to push.</param> /// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param> /// <param name="signature">Identity for use when updating the reflog.</param> /// <param name="logMessage">Message to use when updating the reflog.</param> public virtual void Push( Remote remote, string pushRefSpec, PushOptions pushOptions = null, Signature signature = null, string logMessage = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNullOrEmptyString(pushRefSpec, "pushRefSpec"); Push(remote, new[] { pushRefSpec }, pushOptions, signature, logMessage); }
internal RefSpec(Remote remote, GitRefSpecHandle handle) { this.remote = remote; this.handle = handle; }
/// <summary> /// Fetch from the <see cref="Remote"/>. /// </summary> /// <param name="remote">The remote to fetch</param> /// <param name="options"><see cref="FetchOptions"/> controlling fetch behavior</param> /// <param name="logMessage">Message to use when updating the reflog.</param> public virtual void Fetch(Remote remote, FetchOptions options, string logMessage) { Ensure.ArgumentNotNull(remote, "remote"); DoFetch(repository.Handle, remote, options, logMessage, new string[0]); }
static IEnumerable<DirectReference> GetRemoteTipsUsingUsernamePasswordCredentials(Repository repo, Remote remote, string username, string password) { return repo.Network.ListReferences(remote, (url, fromUrl, types) => new UsernamePasswordCredentials { Username = username, Password = password }).Select(r => r.ResolveToDirectReference()); }
static RemoteSafeHandle BuildRemoteSafeHandle(RepositorySafeHandle repoHandle, Remote remote) { Debug.Assert(repoHandle != null && !repoHandle.IsClosed && !repoHandle.IsInvalid); Debug.Assert(remote != null && remote.Name != null); RemoteSafeHandle remoteHandle = Proxy.git_remote_lookup(repoHandle, remote.Name, true); Debug.Assert(remoteHandle != null && !(remoteHandle.IsClosed || remoteHandle.IsInvalid)); return(remoteHandle); }
/// <summary> /// Push the objectish to the destination reference on the <see cref = "Remote" />. /// </summary> /// <param name="remote">The <see cref = "Remote" /> to push to.</param> /// <param name="objectish">The source objectish to push.</param> /// <param name="destinationSpec">The reference to update on the remote.</param> /// <param name="onPushStatusError">Handler for reporting failed push updates.</param> /// <param name="credentials">Credentials to use for user/pass authentication</param> public virtual void Push( Remote remote, string objectish, string destinationSpec, PushStatusErrorHandler onPushStatusError, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(objectish, "objectish"); Ensure.ArgumentNotNullOrEmptyString(destinationSpec, destinationSpec); Push(remote, string.Format(CultureInfo.InvariantCulture, "{0}:{1}", objectish, destinationSpec), onPushStatusError, credentials); }
/// <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="onPushStatusError">Handler for reporting failed push updates.</param> /// <param name="credentials">Credentials to use for user/pass authentication</param> public virtual void Push( Remote remote, IEnumerable<string> pushRefSpecs, PushStatusErrorHandler onPushStatusError, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs"); // 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; // Return early if there is nothing to push. if (!pushRefSpecs.Any()) { return; } PushCallbacks pushStatusUpdates = new PushCallbacks(onPushStatusError); // Load the remote. using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { 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); } try { Proxy.git_remote_connect(remoteHandle, GitDirection.Push); // Perform the actual push. using (PushSafeHandle pushHandle = Proxy.git_push_new(remoteHandle)) { // Add refspecs. foreach (string pushRefSpec in pushRefSpecs) { Proxy.git_push_add_refspec(pushHandle, pushRefSpec); } Proxy.git_push_finish(pushHandle); if (!Proxy.git_push_unpack_ok(pushHandle)) { throw new LibGit2SharpException("Push failed - remote did not successfully unpack."); } Proxy.git_push_status_foreach(pushHandle, pushStatusUpdates.Callback); Proxy.git_push_update_tips(pushHandle); } } 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); }
internal unsafe RefSpec(Remote remote, git_refspec* handle) { this.remote = remote; this.handle = new IntPtr(handle); }
/// <summary> /// Fetch from the <see cref="Remote"/>, using custom refspecs. /// </summary> /// <param name="remote">The remote to fetch</param> /// <param name="refspecs">Refspecs to use, replacing the remote's fetch refspecs</param> public virtual void Fetch(Remote remote, IEnumerable <string> refspecs) { Fetch(remote, refspecs, null, null); }
/// <summary> /// Push specified reference to the <see cref="Remote"/>. /// </summary> /// <param name="remote">The <see cref = "Remote" /> to push to.</param> /// <param name="pushRefSpec">The pushRefSpec to push.</param> /// <param name="onPushStatusError">Handler for reporting failed push updates.</param> /// <param name="credentials">Credentials to use for user/pass authentication</param> public virtual void Push( Remote remote, string pushRefSpec, PushStatusErrorHandler onPushStatusError, Credentials credentials = null) { Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNullOrEmptyString(pushRefSpec, "pushRefSpec"); Push(remote, new string[] { pushRefSpec }, onPushStatusError, credentials); }
public virtual void Fetch(Remote remote, IEnumerable <string> refspecs, string logMessage) { Commands.Fetch(repository, remote.Name, refspecs, null, logMessage); }
public virtual void Fetch(Remote remote, IEnumerable <string> refspecs, FetchOptions options) { Commands.Fetch(repository, remote.Name, refspecs, options, null); }
public virtual void Fetch(Remote remote, FetchOptions options, string logMessage) { Commands.Fetch(repository, remote.Name, new string[0], options, logMessage); }
/// <summary> /// Fetch from the <see cref="Remote"/>. /// </summary> /// <param name="remote">The remote to fetch</param> /// <param name="options"><see cref="FetchOptions"/> controlling fetch behavior</param> public virtual void Fetch(Remote remote, FetchOptions options) { Fetch(remote, options, null); }