/// <summary> /// /// </summary> /// <returns></returns> public override bool ResolveFiles() { SvnClient client = new SvnClient(); SvnInfoArgs infoArgs = new SvnInfoArgs(); infoArgs.ThrowOnError = false; infoArgs.Depth = SvnDepth.Files; foreach (SourceFile file in State.SourceFiles.Values) { if (file.IsResolved) { continue; } string dirName = SvnTools.GetTruePath(SvnTools.GetNormalizedDirectoryName(file.FullName), true); client.Info(dirName, infoArgs, delegate(object sender, SvnInfoEventArgs e) { SourceFile infoFile; string path = e.FullPath; if (State.SourceFiles.TryGetValue(path, out infoFile) && !infoFile.IsResolved) { infoFile.SourceReference = new SubversionSourceReference(this, infoFile, e.RepositoryRoot, e.RepositoryRoot.MakeRelativeUri(e.Uri), e.LastChangeRevision, e.Revision); } }); } return(true); }
public void Authentication_SimpleSslCert() { using (SvnClient client = new SvnClient()) { client.Authentication.Clear(); client.Authentication.SslServerTrustHandlers += Authenticator_SslServerTrustHandlers; client.Authentication.UserNamePasswordHandlers += Authenticator_UserNamePasswordHandlers; bool arrived = false; SvnInfoArgs a = new SvnInfoArgs(); a.ThrowOnCancel = false; a.ThrowOnError = false; Assert.That(client.Info(new Uri("https://svn.apache.org/repos/private/committers"), a, delegate(object sender, SvnInfoEventArgs e) { arrived = true; }), Is.False); Assert.That(a.LastException, Is.Not.Null); Assert.That(a.LastException, Is.InstanceOf(typeof(SvnException))); Assert.That(arrived, Is.False); Assert.That(_serverTrustTicked); Assert.That(_userNamePasswordTicked); Assert.That(_userArgs, Is.Not.Null); Assert.That(_userArgs.InitialUserName, Is.Not.Null); Assert.That(_userArgs.Realm, Is.EqualTo("<https://svn.apache.org:443> ASF Members")); Assert.That(_userArgs.RealmUri, Is.EqualTo(new Uri("https://svn.apache.org/"))); } }
/// <summary> /// Code taken directly from UpdateAssemblyInfo and the paths slightly modified. /// </summary> /// <remarks> /// The product build version maps to the Subversion revision number. /// </remarks> string GetCurrentRevision() { string revisionNumber = null; string oldWorkingDir = Environment.CurrentDirectory; try { // Set working directory so msvcp70.dll and msvcr70.dll can be found Environment.CurrentDirectory = Path.Combine(applicationFolder, subversionLibraryDir); using (SvnClient client = new SvnClient()) { client.Info( oldWorkingDir, (sender, info) => { revisionNumber = info.Revision.ToString(CultureInfo.InvariantCulture); }); } } catch (Exception e) { Console.WriteLine("Reading revision number with Svn.Net failed: " + e.ToString()); } finally { Environment.CurrentDirectory = oldWorkingDir; } if (revisionNumber == null || revisionNumber.Length == 0 || revisionNumber == "0") { revisionNumber = ReadCurrentRevisionFromFile(); } if (revisionNumber == null || revisionNumber.Length == 0 || revisionNumber == "0") { throw new ApplicationException("Error reading revision number"); } return(revisionNumber); }
static void RetrieveRevisionNumber() { string oldWorkingDir = Environment.CurrentDirectory; try { // Change working dir so that the subversion libraries can be found Environment.CurrentDirectory = Path.Combine(Environment.CurrentDirectory, subversionLibraryDir); using (SvnClient client = new SvnClient()) { client.Info( oldWorkingDir, (sender, info) => { revisionNumber = info.Revision.ToString(CultureInfo.InvariantCulture); }); } } catch (Exception e) { Console.WriteLine("Reading revision number with SharpSvn failed: " + e.ToString()); } finally { Environment.CurrentDirectory = oldWorkingDir; } if (revisionNumber == null || revisionNumber.Length == 0 || revisionNumber == "0") { revisionNumber = ReadRevisionFromFile(); } if (revisionNumber == null || revisionNumber.Length == 0 || revisionNumber == "0") { throw new ApplicationException("Error reading revision number"); } }
public SvnUriTarget GetCopyOrigin(SvnItem item) { if (item == null) { throw new ArgumentNullException("item"); } // TODO: Maybe handle cases where the parent was copied instead of the child? SvnUriTarget copiedFrom = null; using (SvnClient client = GetService <ISvnClientPool>().GetNoUIClient()) { SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; ia.Depth = SvnDepth.Empty; client.Info(item.FullPath, ia, delegate(object sender, SvnInfoEventArgs ee) { if (ee.CopyFromUri != null) { copiedFrom = new SvnUriTarget(ee.CopyFromUri, ee.CopyFromRevision); } }); } return(copiedFrom); }
private void ReadSvnInformation(string url) { try { client.Info(new SvnUriTarget(url, SvnRevision.Head), InfoReceiver); } catch (Exception ex) { OnError(ex); } }
Exception GetNotFoundError() { SvnClient client = new SvnClient(); SvnInfoArgs a = new SvnInfoArgs(); a.ThrowOnError = false; Assert.That(client.Info("c:/does/not/ever/exist/on/windows", a, delegate(object sender, SvnInfoEventArgs e) { }), Is.False, "Should fail"); return(a.LastException); }
bool ItemExists(Uri target) { bool found = false; using (SvnClient client = NewSvnClient(false, false)) { SvnInfoArgs args = new SvnInfoArgs(); args.ThrowOnError = false; args.Depth = SvnDepth.Empty; return(client.Info(target, args, delegate(object sender, SvnInfoEventArgs e) { found = true; }) && found); } }
public void TestSshConnectError() { SvnClient cl = new SvnClient(); SvnRepositoryIOException rio = null; try { cl.Info(new Uri("svn+builtin-ssh://github.com:80"), delegate(object Sender, SvnInfoEventArgs e) { }); } catch (SvnRepositoryIOException e) { rio = e; } Assert.That(rio, Is.Not.Null); SvnSshException sshEx = rio.GetCause <SvnSshException>(); Assert.That(sshEx, Is.Not.Null); Assert.That(sshEx.SshErrorCode, Is.EqualTo(SvnSshErrorCode.LIBSSH2_ERROR_SOCKET_DISCONNECT)); }
public void Authentication_ASFCertSafe() { using (SvnClient client = new SvnClient()) { client.Authentication.Clear(); bool arrived = false; SvnInfoArgs ia = new SvnInfoArgs(); ia.AddExpectedError(SvnErrorCode.SVN_ERR_AUTHN_NO_PROVIDER); ia.AddExpectedError(SvnErrorCode.SVN_ERR_RA_CANNOT_CREATE_SESSION); Assert.That(client.Info(new Uri("https://svn.apache.org/repos/asf/"), ia, delegate(object sender, SvnInfoEventArgs e) { arrived = true; }), Is.False); Assert.That(arrived, Is.False); Assert.That(ia.LastException, Is.Not.Null, "Has exception"); Assert.That(ia.LastException.ContainsError(SvnErrorCode.SVN_ERR_AUTHN_NO_PROVIDER), "Right error code in chain"); } using (SvnClient client = new SvnClient()) { client.Authentication.Clear(); client.Authentication.SslAuthorityTrustHandlers += SvnAuthentication.SubversionWindowsSslAuthorityTrustHandler; client.Authentication.SslServerTrustHandlers += SvnAuthentication.SubversionWindowsSslServerTrustHandler; bool arrived = false; Assert.That(client.Info(new Uri("https://svn.apache.org/repos/asf/"), delegate(object sender, SvnInfoEventArgs e) { arrived = true; })); Assert.That(arrived); } }
public void Authentication_ASFCertSafe() { using (SvnClient client = new SvnClient()) { client.Authentication.Clear(); bool arrived = false; SvnInfoArgs ia = new SvnInfoArgs(); ia.AddExpectedError(SvnErrorCode.SVN_ERR_AUTHN_NO_PROVIDER); ia.AddExpectedError(SvnErrorCode.SVN_ERR_RA_CANNOT_CREATE_SESSION); Assert.That(client.Info(new Uri("https://svn.apache.org/repos/asf/"), ia, delegate(object sender, SvnInfoEventArgs e) { arrived = true; }), Is.False); Assert.That(arrived, Is.False); Assert.That(ia.LastException, Is.Not.Null, "Has exception"); Assert.That(ia.LastException.ContainsError(SvnErrorCode.SVN_ERR_AUTHN_NO_PROVIDER), "Right error code in chain"); } using (SvnClient client = new SvnClient()) { client.Authentication.Clear(); client.Authentication.SslAuthorityTrustHandlers += SvnAuthentication.SubversionWindowsSslAuthorityTrustHandler; client.Authentication.SslServerTrustHandlers += SvnAuthentication.SubversionWindowsSslServerTrustHandler; bool arrived = false; Assert.That(client.Info(new Uri("https://svn.apache.org/repos/asf/"), delegate(object sender, SvnInfoEventArgs e) { arrived = true; })); Assert.That(arrived); } }
public SvnInfo(string path) { _client.Info(SvnTarget.FromString(path), new EventHandler <SvnInfoEventArgs>(OnInfo)); }
Exception GetNotFoundError() { SvnClient client = new SvnClient(); SvnInfoArgs a = new SvnInfoArgs(); a.ThrowOnError = false; Assert.That(client.Info("c:/does/not/ever/exist/on/windows", a, delegate(object sender, SvnInfoEventArgs e) { }), Is.False, "Should fail"); return a.LastException; }
public void Authentication_SimpleSslCert() { using (SvnClient client = new SvnClient()) { client.Authentication.Clear(); client.Authentication.SslServerTrustHandlers += Authenticator_SslServerTrustHandlers; client.Authentication.UserNamePasswordHandlers += Authenticator_UserNamePasswordHandlers; bool arrived = false; SvnInfoArgs a = new SvnInfoArgs(); a.ThrowOnCancel = false; a.ThrowOnError = false; Assert.That(client.Info(new Uri("https://svn.apache.org/repos/private/committers"), a, delegate(object sender, SvnInfoEventArgs e) { arrived = true; }), Is.False); Assert.That(a.LastException, Is.Not.Null); Assert.That(a.LastException, Is.InstanceOf(typeof(SvnException))); Assert.That(arrived, Is.False); Assert.That(_serverTrustTicked); Assert.That(_userNamePasswordTicked); Assert.That(_userArgs, Is.Not.Null); Assert.That(_userArgs.InitialUserName, Is.Not.Null); Assert.That(_userArgs.Realm, Is.EqualTo("<https://svn.apache.org:443> ASF Members")); Assert.That(_userArgs.RealmUri, Is.EqualTo(new Uri("https://svn.apache.org/"))); } }
private void GatherSvnInformation(SvnInformation svn) { Log.LogMessage("Gathering SVN details from " + WorkingCopy); using (var client = new SvnClient()) { var arg = new SvnStatusArgs() { Revision = new SvnRevision(SvnRevisionType.Working), Depth = SvnDepth.Empty }; client.Info(WorkingCopy, (sender, e) => { svn.Now = DateTime.Now; if (String.IsNullOrEmpty(svn.Url)) { svn.Url = e.Uri.AbsoluteUri; } svn.CommitRevision = e.Revision; }); Collection <SvnStatusEventArgs> statuses; arg.Depth = SvnDepth.Infinity; arg.RetrieveAllEntries = true; client.GetStatus(WorkingCopy, arg, out statuses); foreach (var item in statuses) { if (string.IsNullOrEmpty(svn.RootUrl)) { svn.RootUrl = item.RepositoryRoot.AbsoluteUri; } svn.MinRevision = item.Revision > 0 && (item.Revision < svn.MinRevision || svn.MinRevision == 0) ? item.Revision : svn.MinRevision; svn.MaxRevision = item.Revision > 0 && (item.Revision > svn.MaxRevision || svn.MaxRevision == 0) ? item.Revision : svn.MaxRevision; svn.IsSvnItem = false; switch (item.LocalNodeStatus) { case SvnStatus.None: case SvnStatus.NotVersioned: case SvnStatus.Ignored: break; case SvnStatus.External: case SvnStatus.Incomplete: case SvnStatus.Normal: svn.IsSvnItem = true; break; default: svn.IsSvnItem = true; svn.HasModifications = true; break; } switch (item.LocalPropertyStatus) { case SvnStatus.None: case SvnStatus.NotVersioned: case SvnStatus.Ignored: break; case SvnStatus.External: case SvnStatus.Incomplete: case SvnStatus.Normal: svn.IsSvnItem = true; break; default: svn.IsSvnItem = true; svn.HasModifications = true; break; } } svn.MixedRevisions = svn.MinRevision != svn.MaxRevision; svn.RevisionRange = String.Format("{0}:{1}", svn.MinRevision, svn.MaxRevision); } }
public void TestInfo() { SvnSandBox sbox = new SvnSandBox(this); Uri reposUri = sbox.CreateRepository(SandBoxRepository.Empty); Uri WcUri = reposUri; string wc = sbox.Wc; using (SvnClient client = NewSvnClient(true, false)) { client.CheckOut(reposUri, wc); string file = Path.Combine(wc, "InfoFile"); TouchFile(file); client.Add(file); bool visited = false; client.Info(file, delegate(object sender, SvnInfoEventArgs e) { Assert.That(e.ChangeList, Is.Null); Assert.That(e.Checksum, Is.Null); Assert.That(e.ConflictNew, Is.Null); Assert.That(e.ConflictOld, Is.Null); Assert.That(e.ConflictWork, Is.Null); Assert.That(e.ContentTime, Is.EqualTo(DateTime.MinValue)); Assert.That(e.CopyFromRevision, Is.EqualTo(-1L)); Assert.That(e.CopyFromUri, Is.Null); Assert.That(e.Depth, Is.EqualTo(SvnDepth.Unknown)); Assert.That(e.FullPath, Is.EqualTo(file)); Assert.That(e.HasLocalInfo, Is.True); Assert.That(e.LastChangeAuthor, Is.Null); Assert.That(e.LastChangeTime, Is.EqualTo(DateTime.MinValue)); Assert.That(e.LastChangeRevision, Is.EqualTo(-1L), "Not committed yet; LastChangeRevision = -1"); // Not committed yet Assert.That(e.Lock, Is.Null); Assert.That(e.NodeKind, Is.EqualTo(SvnNodeKind.File)); Assert.That(e.Path, Is.Not.Null); Assert.That(e.PropertyEditFile, Is.Null); //Assert.That(e.PropertyTime, Is.EqualTo(DateTime.MinValue)); Assert.That(e.ContentTime, Is.EqualTo(DateTime.MinValue)); Assert.That(e.RepositorySize, Is.EqualTo(-1L)); Assert.That(e.RepositoryRoot, Is.EqualTo(reposUri), "Repository valid"); Assert.That(e.Revision, Is.LessThanOrEqualTo(0L), "Not committed yet"); Assert.That(e.Schedule, Is.EqualTo(SvnSchedule.Add)); Assert.That(e.Uri, Is.EqualTo(new Uri(WcUri, "InfoFile"))); Assert.That(e.WorkingCopySize, Is.EqualTo(-1L)); visited = true; }); Assert.That(visited); SvnCommitResult commitData; client.Commit(wc, out commitData); visited = false; client.Info(file, delegate(object sender, SvnInfoEventArgs e) { Assert.That(e.ChangeList, Is.Null); Assert.That(e.Checksum, Is.EqualTo("da39a3ee5e6b4b0d3255bfef95601890afd80709")); Assert.That(e.ConflictNew, Is.Null); Assert.That(e.ConflictOld, Is.Null); Assert.That(e.ConflictWork, Is.Null); Assert.That(e.ContentTime, Is.GreaterThan(DateTime.UtcNow - new TimeSpan(0, 5, 0))); Assert.That(e.CopyFromRevision, Is.EqualTo(-1L)); Assert.That(e.CopyFromUri, Is.Null); Assert.That(e.Depth, Is.EqualTo(SvnDepth.Unknown)); Assert.That(e.FullPath, Is.EqualTo(file)); Assert.That(e.HasLocalInfo, Is.True); Assert.That(e.LastChangeAuthor, Is.EqualTo(Environment.UserName)); Assert.That(e.LastChangeTime, Is.GreaterThan(DateTime.UtcNow - new TimeSpan(0, 5, 0))); Assert.That(e.LastChangeRevision, Is.EqualTo(commitData.Revision)); Assert.That(e.Lock, Is.Null); Assert.That(e.NodeKind, Is.EqualTo(SvnNodeKind.File)); Assert.That(e.Path, Is.Not.Null); Assert.That(e.PropertyEditFile, Is.Null); //Assert.That(e.PropertyTime, Is.EqualTo(e.ContentTime)); // Not static, might change Assert.That(e.RepositorySize, Is.EqualTo(-1L)); Assert.That(e.RepositoryRoot, Is.EqualTo(reposUri)); Assert.That(e.Revision, Is.EqualTo(commitData.Revision)); Assert.That(e.Schedule, Is.EqualTo(SvnSchedule.Normal)); Assert.That(e.Uri, Is.EqualTo(new Uri(WcUri, "InfoFile"))); Assert.That(e.WorkingCopySize, Is.EqualTo(0L)); visited = true; }); Assert.That(visited); visited = false; client.Info(new Uri(WcUri, "InfoFile"), delegate(object sender, SvnInfoEventArgs e) { Assert.That(e.ChangeList, Is.Null); Assert.That(e.Checksum, Is.Null); Assert.That(e.ConflictNew, Is.Null); Assert.That(e.ConflictOld, Is.Null); Assert.That(e.ConflictWork, Is.Null); Assert.That(e.ContentTime, Is.EqualTo(DateTime.MinValue)); Assert.That(e.CopyFromRevision, Is.LessThanOrEqualTo(0L)); Assert.That(e.CopyFromUri, Is.Null); Assert.That(e.Depth, Is.EqualTo(SvnDepth.Unknown)); Assert.That(e.FullPath, Is.Null); Assert.That(e.HasLocalInfo, Is.False); Assert.That(e.LastChangeAuthor, Is.EqualTo(Environment.UserName)); Assert.That(e.LastChangeTime, Is.GreaterThan(DateTime.UtcNow - new TimeSpan(0, 5, 0))); Assert.That(e.LastChangeTime, Is.LessThan(DateTime.UtcNow + new TimeSpan(0, 5, 0))); Assert.That(e.LastChangeRevision, Is.EqualTo(commitData.Revision)); Assert.That(e.Lock, Is.Null); Assert.That(e.NodeKind, Is.EqualTo(SvnNodeKind.File)); Assert.That(e.Path, Is.Not.Null); Assert.That(e.PropertyEditFile, Is.Null); //Assert.That(e.PropertyTime, Is.EqualTo(e.ContentTime)); Assert.That(e.RepositorySize, Is.EqualTo(0L)); Assert.That(e.RepositoryRoot, Is.EqualTo(reposUri)); Assert.That(e.Revision, Is.EqualTo(commitData.Revision)); Assert.That(e.Schedule, Is.EqualTo(SvnSchedule.Normal)); Assert.That(e.Uri, Is.EqualTo(new Uri(WcUri, "InfoFile"))); Assert.That(e.WorkingCopySize, Is.EqualTo(-1L)); visited = true; }); Assert.That(visited); } }
public void TestSshConnectError() { SvnClient cl = new SvnClient(); SvnRepositoryIOException rio = null; try { cl.Info(new Uri("svn+builtin-ssh://sharpsvn.open.collab.net:80"), delegate(object Sender, SvnInfoEventArgs e) { }); } catch (SvnRepositoryIOException e) { rio = e; } Assert.That(rio, Is.Not.Null); SvnSshException sshEx = rio.GetCause<SvnSshException>(); Assert.That(sshEx, Is.Not.Null); Assert.That(sshEx.SshErrorCode, Is.EqualTo(SvnSshErrorCode.LIBSSH2_ERROR_SOCKET_DISCONNECT)); }
/// <summary> /// /// </summary> /// <returns></returns> public override bool ResolveFiles() { SvnClient client = new SvnClient(); SvnInfoArgs infoArgs = new SvnInfoArgs(); infoArgs.ThrowOnError = false; infoArgs.Depth = SvnDepth.Files; foreach (SourceFile file in State.SourceFiles.Values) { if (file.IsResolved) continue; string dirName = SvnTools.GetTruePath(SvnTools.GetNormalizedDirectoryName(file.FullName), true); client.Info(dirName, infoArgs, delegate(object sender, SvnInfoEventArgs e) { SourceFile infoFile; string path = e.FullPath; if (State.SourceFiles.TryGetValue(path, out infoFile) && !infoFile.IsResolved) { infoFile.SourceReference = new SubversionSourceReference(this, infoFile, e.RepositoryRoot, e.RepositoryRoot.MakeRelativeUri(e.Uri), e.LastChangeRevision, e.Revision); } }); } return true; }
private void GatherSvnInformation( SvnInformation svn ) { using ( var client = new SvnClient() ) { var arg = new SvnStatusArgs() { Revision = new SvnRevision( SvnRevisionType.Working ), Depth = SvnDepth.Empty }; client.Info( WorkingCopy, ( sender, e ) => { svn.Now = DateTime.Now; if ( String.IsNullOrEmpty( svn.Url ) ) svn.Url = e.Uri.AbsoluteUri; svn.CommitRevision = e.Revision; } ); Collection<SvnStatusEventArgs> statuses; arg.Depth = SvnDepth.Infinity; arg.RetrieveAllEntries = true; client.GetStatus( WorkingCopy, arg, out statuses ); foreach ( var item in statuses ) { if ( string.IsNullOrEmpty( svn.RootUrl ) ) svn.RootUrl = item.RepositoryRoot.AbsoluteUri; svn.MinRevision = item.Revision > 0 && ( item.Revision < svn.MinRevision || svn.MinRevision == 0 ) ? item.Revision : svn.MinRevision; svn.MaxRevision = item.Revision > 0 && ( item.Revision > svn.MaxRevision || svn.MaxRevision == 0 ) ? item.Revision : svn.MaxRevision; svn.IsSvnItem = false; switch ( item.LocalNodeStatus ) { case SvnStatus.None: case SvnStatus.NotVersioned: case SvnStatus.Ignored: break; case SvnStatus.External: case SvnStatus.Incomplete: case SvnStatus.Normal: svn.IsSvnItem = true; break; default: svn.IsSvnItem = true; svn.HasModifications = true; break; } switch ( item.LocalPropertyStatus ) { case SvnStatus.None: case SvnStatus.NotVersioned: case SvnStatus.Ignored: break; case SvnStatus.External: case SvnStatus.Incomplete: case SvnStatus.Normal: svn.IsSvnItem = true; break; default: svn.IsSvnItem = true; svn.HasModifications = true; break; } } svn.MixedRevisions = svn.MinRevision != svn.MaxRevision; svn.RevisionRange = String.Format( "{0}:{1}", svn.MinRevision, svn.MaxRevision ); } }