protected override void ExecuteSVNTask(SvnClient client) { if (Dir == null) { Dir = new DirectoryInfo(Project.BaseDirectory); } if (!Dir.Exists) { throw new BuildException(string.Format(Resources.MissingDirectory, Dir.FullName), Location); } string sourcesFolder = string.Concat(Dir.FullName, @"\Sources"); if (Directory.Exists(sourcesFolder)) { Log(Level.Info, Resources.SVNAdding, Dir.FullName); SvnAddArgs addArgs = new SvnAddArgs(); addArgs.Depth = SvnDepth.Infinity; addArgs.Force = true; client.Add(sourcesFolder, addArgs); } else { Log(Level.Info, Resources.SVNSourcesFolderNotFound, sourcesFolder); } Log(Level.Info, Resources.SVNCommitCommitting, Dir.FullName, Message); SvnCommitArgs args = new SvnCommitArgs(); args.LogMessage = Message; args.ThrowOnError = true; SvnCommitResult result; client.Commit(Dir.FullName, args, out result); if (result != null) { Log(Level.Info, Resources.SVNCommitResult, Dir.FullName, result.Revision, result.Author); } }
public void CreateDirectory_CreateTrunk() { SvnSandBox sbox = new SvnSandBox(this); Uri ReposUrl = sbox.CreateRepository(SandBoxRepository.Empty); using (SvnClient client = NewSvnClient(true, false)) { Uri trunkUri = new Uri(ReposUrl, "trunk/"); client.RemoteCreateDirectory(trunkUri); string trunkPath = sbox.Wc; client.CheckOut(trunkUri, trunkPath); TouchFile(Path.Combine(trunkPath, "test.txt")); Assert.That(SvnTools.IsManagedPath(trunkPath)); Assert.That(SvnTools.IsBelowManagedPath(trunkPath)); Assert.That(SvnTools.IsBelowManagedPath(Path.Combine(trunkPath, "q/r/s/t/u/v/test.txt"))); client.Add(Path.Combine(trunkPath, "test.txt")); Directory.CreateDirectory(Path.Combine(trunkPath, "dir")); TouchFile(Path.Combine(trunkPath, "dir/test.txt")); SvnAddArgs aa = new SvnAddArgs(); aa.AddParents = true; client.Add(Path.Combine(trunkPath, "dir/test.txt"), aa); client.Commit(trunkPath); client.RemoteDelete(trunkUri, new SvnDeleteArgs()); } }
public int AddFolder(string localPath) { Trace.TraceInformation("SVNTCAdapter AddFolder {0}", localPath); Directory.CreateDirectory(localPath); m_client.Add(localPath); m_client.Commit(localPath, new SvnCommitArgs() { LogMessage = AddComment }); return(0); }
public void WriteProps() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.Empty); string WcPath = sbox.Wc; string data = Guid.NewGuid().ToString(); using (SvnClient client = NewSvnClient(true, false)) { string file = Path.Combine(WcPath, "WriteTest"); using (StreamWriter sw = File.CreateText(file)) { sw.WriteLine(data); } client.Add(file); client.SetProperty(file, "A", "B"); client.Commit(file); using (MemoryStream ms = new MemoryStream()) { SvnPropertyCollection pc; client.Write(new SvnPathTarget(file, SvnRevision.Head), ms, out pc); Assert.That(pc, Is.Not.Empty); Assert.That(pc["A"].StringValue, Is.EqualTo("B")); } } }
public void Move_MultiMove() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.Empty); string WcPath = sbox.Wc; using (SvnClient client = NewSvnClient(true, false)) { string ren1 = Path.Combine(WcPath, "ren-1"); using (StreamWriter sw = File.CreateText(ren1)) { sw.WriteLine("ToRename"); } client.Add(ren1); client.Commit(WcPath); client.Update(WcPath); using (StreamWriter sw = File.AppendText(ren1)) { sw.WriteLine("AddedLine"); } client.Move(ren1, ren1 + ".ren1"); client.Commit(WcPath); client.Move(ren1 + ".ren1", ren1 + ".ren2"); SvnMoveArgs ma = new SvnMoveArgs(); ma.Force = true; client.Move(ren1 + ".ren2", ren1 + ".ren3", ma); client.Commit(WcPath); } }
public override void Add(FilePath path, bool recurse, IProgressMonitor monitor) { SvnAddArgs args = new SvnAddArgs(); BindMonitor(args, monitor); args.Depth = recurse ? SvnDepth.Infinity : SvnDepth.Empty; client.Add(path, args); }
private List <string> GetChangesetFiles(SvnClient svnClient, Changeset changeset) { List <string> filePaths; filePaths = new List <string>(); foreach (ChangesetFileInfo fileInfo in changeset.Files) { VSSItem versionItem; string filePath; //get version item to get the version of the file versionItem = fileInfo.VssFile.get_Version(fileInfo.VssVersion.VersionNumber); //get the version of the file in question and saves it to the path filePath = fileInfo.FilePath; try { versionItem.Get(ref filePath, (int)(VSSFlags.VSSFLAG_USERRONO | VSSFlags.VSSFLAG_TIMEMOD)); } catch (COMException ex) { // skip if the file couldn't obtained - one of my databases seems to be corrupt and I can't access some files if (!FailedFiles.Contains(fileInfo.FilePath)) { FailedFiles.Add(fileInfo.FilePath); } this.OnLog(new LogEventArgs(ex, string.Format("Could not get version {0} of {1}", fileInfo.VssVersion.VersionNumber, fileInfo.VssFile.Spec))); } if (File.Exists(fileInfo.FilePath)) { // remove VSS bindings //if (this.RemoveVssBindings) <--- always remove VSS bindings from solution VssBindingRemover.RemoveBindings(fileInfo.FilePath); //add the file to SVN if it's not there yet if (fileInfo.IsAdd || FailedFiles.Contains(fileInfo.FilePath)) { try { svnClient.Add(fileInfo.FilePath); this.FailedFiles.Remove(fileInfo.FilePath); // remove from the final failed files collection } catch (SvnEntryException ex) { this.LogException(ex); } } filePaths.Add(fileInfo.FilePath); } } return(filePaths); }
/// <summary> /// 不能添加多层次文件,必须先添加文件夹,在添加指定的文件 /// svn add /// </summary> /// <param name="path">需要添加的目录或者文件</param> public void Add(string path) { using (SvnClient client = new SvnClient()) { SvnAddArgs args = new SvnAddArgs(); args.Force = true; args.Depth = SvnDepth.Infinity; client.Add(path, args); } }
/// <summary> /// 加入版本控制 Add /// </summary> public void AddSvn() { using (SvnClient client = new SvnClient()) { string path = "";// SvnAddArgs args = new SvnAddArgs(); args.Depth = SvnDepth.Empty; client.Add(path, args); } }
public void AddFiles(params string[] files) { using (var svn = new SvnClient()) { foreach (var file in files) { svn.Add(file); } } }
static void AddPathToSubversion(CommandEventArgs e, string path) { using (SvnClient cl = e.GetService <ISvnClientPool>().GetNoUIClient()) { SvnAddArgs aa = new SvnAddArgs(); aa.AddParents = true; aa.AddExpectedError(SvnErrorCode.SVN_ERR_ENTRY_EXISTS); // Don't fail on already added nodes. (<= 1.7) aa.AddExpectedError(SvnErrorCode.SVN_ERR_WC_PATH_FOUND); // Don't fail on already added nodes. (1.8+?) cl.Add(path, aa); } }
public override void AddFile(string Path) { try { client.Add(Path); } catch (Exception e) { Reporter.ToUser(eUserMsgKeys.GeneralErrorOccured, e.Message + Environment.NewLine + e.InnerException); } }
public void Add(string filename, Recurse recurse) { Debug("SVN: Add(" + filename + ", " + recurse + ")"); BeforeWriteOperation("add"); try { client.Add(filename, ConvertDepth(recurse)); } catch (SvnException ex) { throw new SvnClientException(ex); } finally { AfterOperation(); } }
public static long AddFile(ICollection <string> fileNames, string source, string svnUsername, string svnPassword, string comment) { using (SvnClient client = InitializeSvnClient(svnUsername, svnPassword)) { foreach (string filename in fileNames) { client.Add(filename); } return(CommitNGetRevisionNumber(source, comment, client)); } }
public override bool AddFile(string Path, ref string error) { try { client.Add(Path); } catch (Exception e) { error = e.Message + Environment.NewLine + e.InnerException; return(false); } return(true); }
public void WriteTest() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.Empty); string WcPath = sbox.Wc; string data = Guid.NewGuid().ToString(); using (SvnClient client = NewSvnClient(true, false)) { string file = Path.Combine(WcPath, "WriteTest"); using (StreamWriter sw = File.CreateText(file)) { sw.WriteLine(data); } client.Add(file); client.AddToChangeList(file, "WriteTest-Items"); SvnCommitArgs ca = new SvnCommitArgs(); ca.ChangeLists.Add("WriteTest-Items"); client.Commit(WcPath); using (MemoryStream ms = new MemoryStream()) { client.Write(new SvnPathTarget(file), ms); ms.Position = 0; using (StreamReader sr = new StreamReader(ms)) { Assert.That(sr.ReadLine(), Is.EqualTo(data)); Assert.That(sr.ReadToEnd(), Is.EqualTo("")); } } using (MemoryStream ms = new MemoryStream()) { client.Write(new Uri(sbox.RepositoryUri, "WriteTest"), ms); ms.Position = 0; using (StreamReader sr = new StreamReader(ms)) { Assert.That(sr.ReadLine(), Is.EqualTo(data)); Assert.That(sr.ReadToEnd(), Is.EqualTo("")); } } } }
/* * This adds, modifies, and removes index entries to match the working tree. */ public bool AddAll() { /* * var startInfo = GetStartInfo("add -A"); * * // add fails if there are no files (directories don't count) * return ExecuteUnless(startInfo, "did not match any files"); */ var overallStatus = true; using (var client = new SvnClient()) { SvnUI.Bind(client, parentWindow); var statusList = (Collection <SvnStatusEventArgs>)null; var svnStatusArgs = new SvnStatusArgs { Depth = SvnDepth.Infinity, IgnoreExternals = false, KeepDepth = false, RetrieveIgnoredEntries = false }; if (client.GetStatus(useSvnStandardDirStructure ? trunkPath : workingCopyPath, svnStatusArgs, out statusList)) { overallStatus = statusList.Select(svnStatusEventArg => { switch (svnStatusEventArg.LocalNodeStatus) { case SvnStatus.Missing: logger.WriteLine("Commit: Deleting file {0} due to status = {1}", svnStatusEventArg.FullPath, svnStatusEventArg.LocalNodeStatus); return(client.Delete(svnStatusEventArg.FullPath, new SvnDeleteArgs { KeepLocal = false, Force = false })); case SvnStatus.NotVersioned: logger.WriteLine("Commit: Adding file {0} due to status = {1}", svnStatusEventArg.FullPath, svnStatusEventArg.LocalNodeStatus); return(client.Add(svnStatusEventArg.FullPath, new SvnAddArgs { AddParents = false, Depth = SvnDepth.Infinity, Force = false })); default: return(true); } }) .Aggregate(true, (state, val) => state &= val); } else { overallStatus = false; } } return(overallStatus); }
public void StageAll() { using (SvnClient client = new SvnClient()) { Collection <SvnStatusEventArgs> changedFiles = new Collection <SvnStatusEventArgs>(); client.GetStatus(this.repoPath, out changedFiles); SvnAddArgs aa = new SvnAddArgs(); aa.Depth = SvnDepth.Infinity; aa.Force = true; aa.NoIgnore = true; aa.Progress += this.OnProgress; aa.SvnError += this.OnSvnError; aa.Notify += this.OnNotify; SvnDeleteArgs dd = new SvnDeleteArgs(); dd.Force = true; dd.Progress += this.OnProgress; dd.SvnError += this.OnSvnError; dd.Notify += this.OnNotify; foreach (SvnStatusEventArgs changedFile in changedFiles) { if (changedFile.LocalContentStatus == SvnStatus.Missing) { client.Delete(changedFile.Path, dd); } if (changedFile.LocalContentStatus == SvnStatus.NotVersioned) { client.Add(changedFile.Path, aa); } } client.Add(this.repoPath, aa); } }
public void TestCommit() { using (SvnClient client = new SvnClient()) { var localpath = "d:\\sharpsvn\\需求文档\\1.txt"; localpath = "d:\\sharpsvn\\1.txt"; //localpath = @"E:\project\ccms\CCMS_V7_HBYD_R"; var username = "******"; var pwd = "123456"; client.Authentication.DefaultCredentials = new System.Net.NetworkCredential(username, pwd); //如果项目不存在则checkout,否则进行update Console.WriteLine("开始检查是否需要提交新参数表..."); SvnCommitArgs ca = new SvnCommitArgs(); SvnStatusArgs sa = new SvnStatusArgs(); Collection <SvnStatusEventArgs> statuses; client.GetStatus(localpath, sa, out statuses); int i = 0; foreach (var item in statuses) { if (item.LocalContentStatus != item.RemoteContentStatus) { i++; } if (!item.Versioned) { client.Add(item.FullPath); Console.WriteLine("新增加文件" + item.FullPath); i++; } } if (i > 0) { ca.LogMessage = "测试提交文档"; SvnCommitResult clientr; if (client.Commit(localpath, ca, out clientr)) { Console.WriteLine("提交完成"); } else { Console.WriteLine("提交失败"); } } else { Console.WriteLine("无变化,无需检查"); } } }
public bool Add(string path) { /* * var startInfo = GetStartInfo("add -- " + Quote(path)); * * // add fails if there are no files (directories don't count) * return ExecuteUnless(startInfo, "did not match any files"); */ using (var client = new SvnClient()) { SvnUI.Bind(client, parentWindow); return(client.Add(path, new SvnAddArgs { AddParents = false, Depth = SvnDepth.Infinity, Force = true })); } return(false); }
/// <summary> /// Actualiza un archivo en el SVN. /// </summary> /// <param name="ruta"></param> /// <returns></returns> public static string ActualizarArchivo(string nombre, string usuario) { var msj = ""; try { string rutaCopiaTrabajo = ObtenerRutaCopiaTrabajo(); // Argumentos del agregado. var aa = new SvnAddArgs(); aa.Depth = SvnDepth.Infinity; aa.Force = true; // Argyumentos del commit. var args = new SvnCommitArgs(); args.LogMessage = "Editar: " + nombre + ".\nUsuario: " + usuario + ".\nFecha: " + DateTime.Now; args.Depth = SvnDepth.Infinity; using (var client = new SvnClient()) { // Agregar archivo a la copia de trabajo SVN. client.Add(rutaCopiaTrabajo, aa); // Hacer commit repositorio SVN. client.Commit(rutaCopiaTrabajo, args); } msj = "Exito"; } catch (Exception ex) { Debug.WriteLine(ex.ToString()); msj += "Error al subir el archivo: " + ex.Message; if (ex.InnerException != null) { msj += " " + ex.InnerException.Message; } } return(msj); }
private void btnCommit_Click(object sender, EventArgs e) { if (txtSystemCode.Text == "") { return; } var localAppsCSFileVersion = FileVersionInfo.GetVersionInfo(string.Format("d:/APPS_CS/{0}/{1}", txtSystemCode.Text, txtApp.Text)); SvnCommitArgs args = new SvnCommitArgs(); args.LogMessage = string.Format("System {0} version {1} Commit", txtSystemCode, localAppsCSFileVersion.FileVersion); SvnCommitResult result; using (var client = new SvnClient()) { try { SvnUI.Bind(client, this); var addArgs = new SvnAddArgs() { Force = true }; client.Add(string.Format("d:/APPS_CS/{0}", txtSystemCode.Text.ToLower()), addArgs); client.Commit(string.Format("d:/APPS_CS/{0}", txtSystemCode.Text.ToLower()), args, out result); if (result != null) { MessageBox.Show("Successfully commited revision " + result.Revision); } else { MessageBox.Show("No changes have been made to working copy since it was checked out."); } } catch (SvnException se) { MessageBox.Show(se.Message + "Error: " + se.SvnErrorCode + Environment.NewLine, "svn commit error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// Adds a file to be committed /// </summary> /// <param name="filePath"></param> /// <returns></returns> public bool Add(string filePath) { var returnValue = false; var svnAddArgs = new SvnAddArgs(); svnAddArgs.Depth = SvnDepth.Empty; svnAddArgs.AddParents = true; var status = GetSingleItemStatus(filePath); if (status.IsVersionable && !status.IsVersioned) { returnValue = _svnClient.Add(filePath, svnAddArgs); if (returnValue) { UpdateCache(filePath); } } return(returnValue); }
public void Sync() { _svnAdd = new List <FileSystemInfo>(); _svnDelete = new List <FileSystemInfo>(); FolderSync sync = new FolderSync(_args.Source, _args.Destination, FileActions.Ask, FileActions.Ask, FileActions.Ask); sync.AskWhatToDo += new AskWhatToDoDelegate(sync_AskWhatToDo); sync.ErrorEvent += new ErrorDelegate(sync_ErrorEvent); sync.Sync(); Console.WriteLine("Applying {0} svn delete changes ...", _svnDelete.Count); foreach (FileSystemInfo si in _svnDelete) { Console.WriteLine(" D {0}", si.FullName); if (!_args.simulationOnly) { SvnDeleteArgs svnDeleteArgs = new SvnDeleteArgs(); svnDeleteArgs.ThrowOnError = true; svnDeleteArgs.Force = true; _client.Delete(si.FullName, svnDeleteArgs); } } Console.WriteLine("Applying {0} svn add changes ...", _svnAdd.Count); foreach (FileSystemInfo si in _svnAdd) { Console.WriteLine(" A {0}", si.FullName); if (!_args.simulationOnly) { SvnAddArgs svnAddArgs = new SvnAddArgs(); svnAddArgs.ThrowOnError = true; svnAddArgs.Depth = SvnDepth.Empty; _client.Add(si.FullName, svnAddArgs); } } }
public void Move_BasicMove() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.Empty); string WcPath = sbox.Wc; Uri ReposUrl = sbox.RepositoryUri; string TestPath = sbox.GetTempDir(); using (SvnClient client = NewSvnClient(true, false)) { string file = Path.Combine(WcPath, "LocalMoveBase"); TouchFile(file); client.Add(file); Directory.CreateDirectory(Path.Combine(TestPath, "MoveTestImport")); TouchFile(Path.Combine(TestPath, "MoveTestImport/RemoteMoveBase")); client.RemoteImport(Path.Combine(TestPath, "MoveTestImport"), new Uri(ReposUrl, "RemoteMoveBase")); client.Commit(WcPath); Assert.That(ItemExists(new Uri(ReposUrl, "RemoteMoveBase")), Is.True, "Remote base does exist"); Assert.That(ItemExists(new Uri(ReposUrl, "LocalMoveBase")), Is.True, "Local base does exist"); client.RemoteMove(new Uri(ReposUrl, "RemoteMoveBase"), new Uri(ReposUrl, "RemoteMoveTarget")); client.Move(file, Path.Combine(WcPath, "LocalMoveTarget")); client.Commit(WcPath); Assert.That(ItemExists(new Uri(ReposUrl, "RemoteMoveTarget")), Is.True, "Remote target exists"); Assert.That(ItemExists(new Uri(ReposUrl, "LocalMoveTarget")), Is.True, "Local target exists"); Assert.That(ItemExists(new Uri(ReposUrl, "RemoteMoveBase")), Is.False, "Remote base does not exist"); Assert.That(ItemExists(new Uri(ReposUrl, "LocalMoveBase")), Is.False, "Local base does not exist"); } }
public void Move_MoveAndEdit() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.Empty); string WcPath = sbox.Wc; using (SvnClient client = NewSvnClient(true, false)) { string file = Path.Combine(WcPath, "LMB"); TouchFile(file); client.Add(file); File.AppendAllText(Path.Combine(WcPath, "LMB"), "Banana" + Environment.NewLine); client.Move(file, Path.Combine(WcPath, "LMB2")); File.AppendAllText(Path.Combine(WcPath, "LMB2"), "Banana" + Environment.NewLine); client.Commit(WcPath); } }
//处理有问题的文件 public void QuestionFile(string path) { // string path = "D:\\Test"; //SvnClient client = new SvnClient(); SvnStatusArgs sa = new SvnStatusArgs(); Collection <SvnStatusEventArgs> status; _client.GetStatus(path, sa, out status); foreach (var item in status) { string fPath = item.FullPath; if (item.LocalContentStatus != item.RemoteContentStatus) { //被修改了的文件 } if (!item.Versioned) { //新增文件 _client.Add(fPath); } else if (item.Conflicted) { //将冲突的文件用工作文件解决冲突 _client.Resolve(fPath, SvnAccept.Working); } else if (item.IsRemoteUpdated) { //更新来自远程的新文件 _client.Update(fPath); } else if (item.LocalContentStatus == SvnStatus.Missing) { //删除丢失的文件 _client.Delete(fPath); } } }
public void Export_Forced() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.Default); string WcPath = sbox.Wc; Uri WcUri = sbox.Uri; string exportDir = Path.Combine(sbox.GetTempDir("ExportTests"), "exportTo"); using (SvnClient client = NewSvnClient(true, false)) { string file = Path.Combine(WcPath, "ExportFile"); TouchFile(file); client.Add(file); client.Commit(WcPath); Assert.That(Directory.Exists(exportDir), Is.False); client.Export(WcUri, exportDir); Assert.That(Directory.Exists(exportDir), Is.True); Assert.That(File.Exists(Path.Combine(exportDir, "ExportFile"))); Assert.That(!Directory.Exists(Path.Combine(exportDir, ".svn"))); ForcedDeleteDirectory(exportDir); Assert.That(Directory.Exists(exportDir), Is.False); client.Export(new SvnPathTarget(WcPath), exportDir); Assert.That(Directory.Exists(exportDir), Is.True); Assert.That(File.Exists(Path.Combine(exportDir, "ExportFile"))); ForcedDeleteDirectory(exportDir); } }
public bool Add(string path) { /* var startInfo = GetStartInfo("add -- " + Quote(path)); // add fails if there are no files (directories don't count) return ExecuteUnless(startInfo, "did not match any files"); */ using (var client = new SvnClient()) { SvnUI.Bind(client, parentWindow); return client.Add(path, new SvnAddArgs { AddParents = false, Depth = SvnDepth.Infinity, Force = true }); } return false; }
/* * This adds, modifies, and removes index entries to match the working tree. */ public bool AddAll() { /* var startInfo = GetStartInfo("add -A"); // add fails if there are no files (directories don't count) return ExecuteUnless(startInfo, "did not match any files"); */ var overallStatus = true; using (var client = new SvnClient()) { SvnUI.Bind(client, parentWindow); var statusList = (Collection<SvnStatusEventArgs>)null; var svnStatusArgs = new SvnStatusArgs { Depth = SvnDepth.Infinity, IgnoreExternals = false, KeepDepth = false, RetrieveIgnoredEntries = false }; if (client.GetStatus(useSvnStandardDirStructure ? trunkPath : workingCopyPath, svnStatusArgs, out statusList)) { overallStatus = statusList.Select(svnStatusEventArg => { switch (svnStatusEventArg.LocalNodeStatus) { case SvnStatus.Missing: logger.WriteLine("Commit: Deleting file {0} due to status = {1}", svnStatusEventArg.FullPath, svnStatusEventArg.LocalNodeStatus); return client.Delete(svnStatusEventArg.FullPath, new SvnDeleteArgs { KeepLocal = false, Force = false }); case SvnStatus.NotVersioned: logger.WriteLine("Commit: Adding file {0} due to status = {1}", svnStatusEventArg.FullPath, svnStatusEventArg.LocalNodeStatus); return client.Add(svnStatusEventArg.FullPath, new SvnAddArgs { AddParents = false, Depth = SvnDepth.Infinity, Force = false }); default: return true; } }) .Aggregate(true, (state, val) => state &= val); } else overallStatus = false; } return overallStatus; }
public static void Checkout(string repoDir, string wcDir) { if (Directory.Exists(wcDir)) { Directory.Delete(wcDir, true); } using (var svn = new SvnClient()) { var repoUri = new Uri("file:///" + repoDir.Replace('\\', '/')); svn.CheckOut(new SvnUriTarget(repoUri), wcDir); foreach (var fse in Directory.EnumerateFileSystemEntries(wcDir)) { if (Path.GetFileName(fse).ToLowerInvariant() == ".svn") continue; svn.Add(fse, SvnDepth.Infinity); } svn.Commit(wcDir, new SvnCommitArgs { LogMessage = "PreCreate revision" }); } }
/// <summary> /// Initialize the Subversion adapter based on the TestEnvironment and the test EndPoint data /// </summary> /// <param name="endPoint"></param> public void Initialize(MigrationTestLibrary.EndPoint endPoint) { Trace.TraceInformation("SubversionTCAdapter: Initialize BEGIN"); m_serverUri = new Uri(endPoint.ServerUrl, UriKind.Absolute); foreach (Setting s in endPoint.CustomSettingsList) { if (String.Equals(s.Key, "Username", StringComparison.OrdinalIgnoreCase)) { m_userName = s.Value; } if (String.Equals(s.Key, "Password", StringComparison.OrdinalIgnoreCase)) { m_password = s.Value; } } if (String.IsNullOrEmpty(m_userName)) { m_userName = Environment.UserName; endPoint.CustomSettingsList.Add(new Setting() { Key = "Username", Value = m_userName }); } Trace.TraceInformation("Using SVN username '{0}'", m_userName); if (String.IsNullOrEmpty(m_password)) { m_password = m_userName; endPoint.CustomSettingsList.Add(new Setting() { Key = "Password", Value = m_password }); } // set these values to something so the product code doesn't complain later endPoint.TeamProject = "unusedSVNProjectName"; //Create a new instance of the svn client m_client = new SvnClient(); Trace.TraceInformation("Setting SVN credentials"); //Use the credentials if we have any if (!string.IsNullOrEmpty(m_userName)) { m_client.Authentication.DefaultCredentials = new NetworkCredential(m_userName, m_password); } //Ensure that we can access the repository. The easist way is to query any information. We will receive an exception if a connection cannot be established //Trace.TraceInformation("Testing SVN access"); //m_client.GetRepositoryRoot(m_serverUri); // endPoint.ServerUrl includes the repository string serverRoot = endPoint.ServerUrl; string localRoot = endPoint.LocalStorageLocation; if (String.IsNullOrEmpty(localRoot)) { localRoot = Environment.ExpandEnvironmentVariables(@"%systemdrive%\SvnTest"); } Directory.CreateDirectory(localRoot); // now map the 'mt' test folder, adding it if it does not exist string serverTestRootFolder = String.Format("{0}/{1}", serverRoot, "tests"); string localTestRootFolder = String.Format(@"{0}\{1}", localRoot, "tests"); // assume that the test root folder is already in SVN try { Trace.TraceInformation("Checking out SVN test root folder"); m_client.CheckOut(new SvnUriTarget(serverTestRootFolder), localTestRootFolder); } catch (SharpSvn.SvnRepositoryIOException) { Trace.TraceInformation("Adding base test folder to SVN: {0} -> {1}", localRoot, serverRoot); // backup and map just the root Trace.TraceInformation("Checking out SVN root folder"); m_client.CheckOut(new SvnUriTarget(serverRoot), localRoot); // create and map the main test folder Directory.CreateDirectory(localTestRootFolder); m_client.Add(localTestRootFolder); m_client.Commit(localTestRootFolder, new SvnCommitArgs() { LogMessage = "Adding automated tests root folder" }); Trace.TraceInformation("Committed SVN root folder"); } // create the new folder specific for this test string testFolder = String.Format(@"{0}.{1}", DateTime.Now.ToString("yyyyMMdd.HHmmss"), endPoint.TestName); m_filterPath = String.Format(@"/{0}/{1}", "tests", testFolder); m_localPath = String.Format(@"{0}\{1}", localTestRootFolder, testFolder); string serverTestFolder = String.Format("{0}/{1}", serverTestRootFolder, testFolder); //m_filterPath = serverTestFolder; Directory.CreateDirectory(m_localPath); Trace.TraceInformation("Adding test folder to SVN: {0} -> {1}", m_localPath, serverTestFolder); m_client.Add(m_localPath); m_client.Commit(m_localPath, new SvnCommitArgs() { LogMessage = "Adding test folder" }); Trace.TraceInformation("Committed test folder for this test"); Trace.TraceInformation("m_workspaceLocalPath: {0}", m_localPath); Trace.TraceInformation("m_filterPath: {0}", m_filterPath); Trace.TraceInformation("SubversionTCAdapter: Initialize END"); }
internal void HandleEvent(AnkhCommand command) { List <SccProject> dirtyProjects; HybridCollection <string> dirtyCheck; HybridCollection <string> maybeAdd; SvnSccProvider provider = GetService <SvnSccProvider>(); lock (_lock) { _posted = false; _onIdle = false; if (provider == null) { return; } dirtyProjects = _dirtyProjects; dirtyCheck = _dirtyCheck; maybeAdd = _maybeAdd; _dirtyProjects = null; _dirtyCheck = null; _maybeAdd = null; } if (dirtyCheck != null) { foreach (string file in dirtyCheck) { DocumentTracker.CheckDirty(file); } } if (dirtyProjects != null) { foreach (SccProject project in dirtyProjects) { if (project.IsSolution) { provider.UpdateSolutionGlyph(); } else { project.NotifyGlyphChanged(); } } } if (maybeAdd != null) { using (SvnClient cl = GetService <ISvnClientPool>().GetNoUIClient()) { foreach (string file in maybeAdd) { SvnItem item = SvnCache[file]; // Only add // * files // * that are unversioned // * that are addable // * that are not ignored // * and just to be sure: that are still part of the solution if (item.IsFile && !item.IsVersioned && item.IsVersionable && !item.IsIgnored && item.InSolution && !item.IsSccExcluded) { SvnAddArgs aa = new SvnAddArgs(); aa.ThrowOnError = false; // Just ignore errors here; make the user add them themselves aa.AddParents = true; if (cl.Add(item.FullPath, aa)) { item.MarkDirty(); // Detect if we have a file that Subversion might detect as binary if (item.IsVersioned && !item.IsTextFile) { // Only check small files, avoid checking big binary files FileInfo fi = new FileInfo(item.FullPath); if (fi.Length < 10) { // We're sure it's at most 10 bytes here, so just read all byte[] fileBytes = File.ReadAllBytes(item.FullPath); // If the file starts with a UTF8 BOM, we're sure enough it's a text file, keep UTF16 & 32 binary if (StartsWith(fileBytes, new byte[] { 0xEF, 0xBB, 0xBF })) { // Delete the mime type property, so it's detected as a text file again SvnSetPropertyArgs pa = new SvnSetPropertyArgs(); pa.ThrowOnError = false; cl.DeleteProperty(item.FullPath, SvnPropertyNames.SvnMimeType, pa); } } } } } } } } }
public void Copy() { long lastSyncRevision = 0; if (_args.Incremental) { SvnLogParser logParser = new SvnLogParser(_args.Destination); lastSyncRevision = logParser.GetLastSyncedRevisionFromDestination(); Console.WriteLine("Last revision synched: {0}", lastSyncRevision); } Console.Write("Collecting svn log: "); if (_args.RevisionRange != null) { Console.Write("{0}:{1} ", _args.RevisionRange.StartRevision, _args.RevisionRange.EndRevision); } // fetch the source svn respository and SvnInfo sourceInfo = new SvnInfo(_args.Source); Console.WriteLine("Source SVN root: {0}", sourceInfo.Info.RepositoryRoot); Console.WriteLine("Source SVN uri: {0}", sourceInfo.Info.Uri); string sourceRelativePath = sourceInfo.Info.Uri.ToString().Remove( 0, sourceInfo.Info.RepositoryRoot.ToString().Length - 1); Console.WriteLine("Relative path: {0}", sourceRelativePath); if (!string.IsNullOrEmpty(_args.Root)) { sourceRelativePath = _args.Root; Console.WriteLine("Substituting relative path: {0}", sourceRelativePath); } SvnLogArgs logArgs = new SvnLogArgs(); logArgs.StrictNodeHistory = _args.StopOnCopy; logArgs.ThrowOnError = true; logArgs.Range = _args.RevisionRange; logArgs.RetrieveChangedPaths = true; _client.Log(_args.Source, logArgs, new EventHandler <SvnLogEventArgs>(OnLog)); Console.WriteLine(); Console.WriteLine("Collected {0} revisions.", _revisions.Count); SvnTarget fromSvnTarget = SvnTarget.FromString(_args.Source); foreach (KeyValuePair <long, SvnLogEventArgs> revisionPair in _revisions) { SvnLogEventArgs revision = revisionPair.Value; if (_args.Incremental && lastSyncRevision != 0 && lastSyncRevision >= revision.Revision) { Console.WriteLine("Skipping revision {0} ({1})", revision.Revision, revision.Time); continue; } Console.WriteLine("Revision {0} ({1})", revision.Revision, revision.Time); if (_args.SimulationOnly) { continue; } SvnExportArgs exportArgs = new SvnExportArgs(); exportArgs.Overwrite = true; exportArgs.ThrowOnError = true; exportArgs.Revision = revision.Revision; SvnUpdateResult exportResult = null; _client.Export(fromSvnTarget, _args.Destination, exportArgs, out exportResult); if (revision.ChangedPaths == null) { throw new Exception(string.Format("No changed paths in rev. {0}", revision.Revision)); } SortedList <string, SvnChangeItem> changeItems = new SortedList <string, SvnChangeItem>(); foreach (SvnChangeItem changeItem in revision.ChangedPaths) { changeItems.Add(changeItem.Path, changeItem); } List <string> filesAdd = new List <string>(); List <string> filesDelete = new List <string>(); List <string> filesModify = new List <string>(); // add files in forward order (add directories first) // delete files in reverse order (delete files first) foreach (SvnChangeItem changeItem in changeItems.Values) { // anything above (outside) of the source path is ignored, we didn't export that if (!changeItem.Path.StartsWith(sourceRelativePath)) { Console.WriteLine("Skipping {0}. Did you need to specify /root:<path>?)", changeItem.Path); continue; } string targetSvnPath = changeItem.Path.Remove(0, sourceRelativePath.Length); string targetOSPath = targetSvnPath.Replace("/", @"\"); string targetPath = Path.Combine(_args.Destination, targetOSPath); Console.WriteLine(" {0} {1}", changeItem.Action, changeItem.Path); switch (changeItem.Action) { case SvnChangeAction.Add: case SvnChangeAction.Replace: filesAdd.Add(targetPath); break; case SvnChangeAction.Delete: filesDelete.Insert(0, targetPath); break; case SvnChangeAction.Modify: filesModify.Add(targetPath); break; } } Console.WriteLine("Applying changes @ rev. {0} ...", revision.Revision); foreach (string targetPath in filesModify) { Console.WriteLine(" M {0}", targetPath); } foreach (string targetPath in filesAdd) { if (!File.Exists(targetPath)) { throw new Exception(string.Format("Added file '{0}' doesn't exist. Did you need to specify /root:<path>?", targetPath)); } Console.WriteLine(" A {0}", targetPath); SvnAddArgs svnAddArgs = new SvnAddArgs(); svnAddArgs.ThrowOnError = true; svnAddArgs.Depth = SvnDepth.Empty; _client.Add(targetPath, svnAddArgs); } foreach (string targetPath in filesDelete) { Console.WriteLine(" D {0}", targetPath); SvnDeleteArgs svnDeleteArgs = new SvnDeleteArgs(); svnDeleteArgs.ThrowOnError = true; svnDeleteArgs.Force = true; _client.Delete(targetPath, svnDeleteArgs); } SvnCommitArgs commitArgs = new SvnCommitArgs(); commitArgs.LogMessage = revision.LogMessage; commitArgs.LogMessage += string.Format("\nCopied from {0}, rev. {1} by {2} @ {3} {4}", sourceInfo.Info.Uri, revision.Revision, revision.Author, revision.Time.ToShortDateString(), revision.Time.ToShortTimeString()); commitArgs.ThrowOnError = true; Console.WriteLine("Committing changes @ rev. {0} in {1}", revision.Revision, _args.Destination); Console.WriteLine("----------------------------------------------------------------------------"); Console.WriteLine(commitArgs.LogMessage); Console.WriteLine("----------------------------------------------------------------------------"); if (_args.Prompt) { while (true) { Console.Write("Commit? [Y/N] "); char k = Char.ToLower(Console.ReadKey().KeyChar); Console.WriteLine(); if (k == 'y') { break; } if (k == 'n') { throw new Exception("Aborted by user."); } } } SvnCommitResult commitResult = null; _client.Commit(_args.Destination, commitArgs, out commitResult); if (commitResult != null) { Console.WriteLine("Commited revision {0}.", commitResult.Revision); } else { Console.WriteLine("There were no committable changes."); Console.WriteLine("Subversion property changes are not supported."); } } }
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); } }