Exemplo n.º 1
1
        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);
            }
        }
Exemplo n.º 2
0
        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());
            }
        }
Exemplo n.º 3
0
        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());
            }
        }
Exemplo n.º 4
0
        public void Add_BasicAdd()
        {
            SvnSandBox sbox = new SvnSandBox(this);

            sbox.Create(SandBoxRepository.Default);

            string dir      = sbox.Wc;
            string testFile = Path.Combine(dir, "testfile.txt");

            File.WriteAllText(testFile, "This is a testfile");

            SvnAddArgs a = new SvnAddArgs();

            a.Depth = SvnDepth.Empty;

            Client.Add(testFile, a);

            // Check if the file is part of a working copy
            Guid g;

            Assert.That(Client.TryGetRepositoryId(testFile, out g));
            Assert.That(g, Is.Not.EqualTo(Guid.Empty));

            Collection <SvnStatusEventArgs> st;

            Client.GetStatus(testFile, out st);

            Assert.That(st.Count, Is.EqualTo(1));
            Assert.That(st[0].LocalNodeStatus, Is.EqualTo(SvnStatus.Added));

            Client.Configuration.LogMessageRequired = false;
            Assert.That(Client.Commit(dir));
        }
Exemplo n.º 5
0
        public void Add_AddWithForce()
        {
            SvnSandBox sbox = new SvnSandBox(this);

            sbox.Create(SandBoxRepository.Default);
            string WcPath = sbox.Wc;

            SvnAddArgs a = new SvnAddArgs();

            a.Depth = SvnDepth.Empty;

            string file = Path.Combine(WcPath, "AssemblyInfo.cs");

            TouchFile(file);
            this.Client.Add(file);
            try
            {
                this.Client.Add(file, a);
                Assert.Fail("Should have failed");
            }
            catch (SvnException)
            {
                // swallow
            }

            // should not fail
            a.Force = true;
            this.Client.Add(file, a);
        }
Exemplo n.º 6
0
        public void Add_AddDirectoryRecursively()
        {
            SvnSandBox sbox = new SvnSandBox(this);

            sbox.Create(SandBoxRepository.Default);
            string WcPath = sbox.Wc;

            string dir1, dir2, testFile1, testFile2;

            CreateSubdirectories(WcPath, out dir1, out dir2, out testFile1, out testFile2);

            this.Client.Notify += new EventHandler <SvnNotifyEventArgs>(this.NotifyCallback);
            // now a recursive add
            SvnAddArgs a = new SvnAddArgs();

            a.Depth = SvnDepth.Infinity;
            this.Client.Add(dir1, a);

            // enough notifications?
            Assert.That(this.Notifications.Length, Is.EqualTo(4), "Received wrong number of notifications");
            Assert.That(this.GetSvnStatus(dir1), Is.EqualTo(SvnStatus.Added), "Subdirectory not added");
            Assert.That(this.GetSvnStatus(dir2), Is.EqualTo(SvnStatus.Added), "Subsubdirectory not added");
            Assert.That(this.GetSvnStatus(testFile1), Is.EqualTo(SvnStatus.Added), "File in subdirectory not added");
            Assert.That(this.GetSvnStatus(testFile2), Is.EqualTo(SvnStatus.Added), "File in subsubdirectory not added");
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Adds all files which are marked as to be added to subversion
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns></returns>
        private bool PreCommit_AddNewFiles(PendingCommitState state)
        {
            Queue <string> toAdd = new Queue <string>();

            foreach (PendingChange pc in state.Changes)
            {
                if (pc.Change != null &&
                    (pc.Change.State == PendingChangeKind.New ||
                     pc.Change.State == PendingChangeKind.DeletedNew))
                {
                    SvnItem item = pc.SvnItem;

                    // HACK: figure out why PendingChangeKind.New is still true
                    if (item.IsVersioned && !item.IsDeleteScheduled)
                    {
                        continue; // No need to add
                    }
                    toAdd.Enqueue(item.FullPath);
                }
            }
            while (toAdd.Count > 0)
            {
                SvnException error = null;

                state.GetService <IProgressRunner>().RunModal(PccStrings.AddingTitle,
                                                              delegate(object sender, ProgressWorkerArgs e)
                {
                    SvnAddArgs aa   = new SvnAddArgs();
                    aa.AddParents   = true;
                    aa.Depth        = SvnDepth.Empty;
                    aa.ThrowOnError = false;

                    while (toAdd.Count > 0)
                    {
                        if (!e.Client.Add(toAdd.Dequeue(), aa))
                        {
                            error = aa.LastException;
                            break;
                        }
                    }
                });

                if (error != null)
                {
                    if (error.SvnErrorCode == SvnErrorCode.SVN_ERR_WC_UNSUPPORTED_FORMAT)
                    {
                        state.MessageBox.Show(error.Message + Environment.NewLine + Environment.NewLine
                                              + PccStrings.YouCanDownloadAnkh, "", MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        return(false);
                    }
                    else if (state.MessageBox.Show(error.Message, "", MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Error) != DialogResult.OK)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 9
0
 /// <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);
     }
 }
Exemplo n.º 10
0
        internal void AddParents(string newParent)
        {
            SvnAddArgs aa = new SvnAddArgs();

            aa.AddParents   = true;
            aa.ThrowOnError = false;
            aa.Depth        = SvnDepth.Empty;

            Client.Add(SvnTools.GetNormalizedDirectoryName(newParent), aa);
        }
Exemplo n.º 11
0
        public override void Add(FilePath path, bool recurse, IProgressMonitor monitor)
        {
            var args = new SvnAddArgs {
                Depth = recurse ? SvnDepth.Infinity : SvnDepth.Empty,
            };

            BindMonitor(monitor);
            lock (client)
                client.Add(path, args);
        }
Exemplo n.º 12
0
 /// <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);
     }
 }
Exemplo n.º 13
0
 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);
     }
 }
Exemplo n.º 14
0
        public void AddFolder(string path)
        {
            if (path != this.workingCopyPath)
            {
                this.AddMissingDirectoryIfNeeded(path);

                SvnAddArgs addArgs = new SvnAddArgs();
                addArgs.Depth          = SvnDepth.Empty;
                addArgs.ThrowOnError   = false;
                addArgs.ThrowOnWarning = false;
                this.svnClient.Add(path, addArgs);
            }
        }
Exemplo n.º 15
0
        public void Add_AddFileWithNonAsciiFilename()
        {
            SvnSandBox sbox = new SvnSandBox(this);

            sbox.Create(SandBoxRepository.Default);
            string     WcPath = sbox.Wc;
            SvnAddArgs a      = new SvnAddArgs();

            a.Depth = SvnDepth.Infinity;

            string newFile = Path.Combine(WcPath, "eia.");

            File.Create(newFile).Close();
            this.Client.Add(newFile, a);
        }
Exemplo n.º 16
0
        public bool SvnAdd(string path)
        {
            return(DoWithSvn(path, svnClient => {
                svnClient.Authentication.DefaultCredentials = _svnCredentials;
                var args = new SvnAddArgs {
                    Depth = SvnDepth.Infinity, AddParents = true
                };
                var result = svnClient.Add(path, args);
                if (result)
                {
                    Log.ShowLog($"SharpSvn has added {path}");
                }

                return result;
            }));
        }
Exemplo n.º 17
0
        public void Add_MultiLevelAdd()
        {
            SvnSandBox sbox = new SvnSandBox(this);

            sbox.Create(SandBoxRepository.Empty);

            string subdir = Path.Combine(sbox.Wc, "trunk/a/b/c");

            Directory.CreateDirectory(Path.Combine(sbox.Wc, "trunk/a/b/c"));

            SvnAddArgs aa = new SvnAddArgs();

            aa.Force      = true; // Continue
            aa.AddParents = true;

            Client.Add(subdir, aa);

            Client.Commit(sbox.Wc);
        }
Exemplo n.º 18
0
        /// <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);
        }
Exemplo n.º 19
0
        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);
                }
            }
        }
Exemplo n.º 20
0
        /// <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);
        }
Exemplo n.º 21
0
        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);
                }
            }
        }
Exemplo n.º 22
0
        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);
            }
        }
Exemplo n.º 23
0
        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);
                }                
            }
        }
Exemplo n.º 24
0
        private void AddMissingDirectoryIfNeeded(string path)
        {
            string directory = Directory.GetParent(path).FullName;

            if (Directory.Exists(directory))
            {
                return;
            }

            Log.Info("Adding: " + directory);
            Directory.CreateDirectory(directory);
            string workingCopyDirectory;

            if (!this.workingCopyPath.EndsWith("\\"))
            {
                workingCopyDirectory = Directory.GetParent(this.workingCopyPath + '\\').FullName;
            }
            else
            {
                workingCopyDirectory = Directory.GetParent(this.workingCopyPath).FullName;
            }

            string[] pathParts = directory.Substring(workingCopyDirectory.Length).Split('\\');

            foreach (string pathPart in pathParts)
            {
                workingCopyDirectory += '\\';
                workingCopyDirectory += pathPart;

                SvnAddArgs addArgs = new SvnAddArgs();
                addArgs.Depth          = SvnDepth.Empty;
                addArgs.ThrowOnError   = false;
                addArgs.ThrowOnWarning = false;
                this.svnClient.Add(workingCopyDirectory, addArgs);
            }
        }
Exemplo n.º 25
0
        public void TestAddWithParents()
        {
            SvnSandBox sbox = new SvnSandBox(this);

            sbox.Create(SandBoxRepository.Empty);
            string dir = sbox.Wc;

            string file = Path.Combine(dir, "a/b/d/e/f");

            Directory.CreateDirectory(Path.Combine(dir, "a/b/d/e"));
            TouchFile(file);

            SvnAddArgs aa = new SvnAddArgs();

            aa.ThrowOnError = false;
            //aa.AddParents = true;
            Assert.That(Client.Add(file, aa), Is.False);

            aa.ThrowOnError = true;
            aa.AddParents   = true;

            Assert.That(Client.Add(file, aa));

            Client.Info(file, delegate(object sender, SvnInfoEventArgs e)
            {
                // This check verifies Subversion 1.5 behavior, but will probably
                // give the real guid in 1.6+
                Assert.That(e.RepositoryId, Is.Not.EqualTo(Guid.Empty));
            });

            Guid gg;

            Assert.That(Client.TryGetRepositoryId(file, out gg));

            Assert.That(gg, Is.Not.EqualTo(Guid.Empty));
        }
Exemplo n.º 26
0
        public void Add_AddDirectoryNonRecursively()
        {
            SvnSandBox sbox = new SvnSandBox(this);

            sbox.Create(SandBoxRepository.Empty);

            string dir1, dir2, testFile1, testFile2;

            CreateSubdirectories(sbox.Wc, out dir1, out dir2, out testFile1, out testFile2);

            this.Client.Notify += new EventHandler <SvnNotifyEventArgs>(this.NotifyCallback);
            SvnAddArgs a = new SvnAddArgs();

            a.Depth = SvnDepth.Empty;
            // do a non-recursive add here
            this.Client.Add(dir1, a);

            Assert.That(this.Notifications.Length == 1, "Too many or no notifications received. Added recursively?");
            Assert.That(this.GetSvnStatus(dir1), Is.EqualTo(SvnStatus.Added), "Subdirectory not added");

            Assert.That(GetSvnStatus(dir2), Is.Not.EqualTo(SvnStatus.Added), "Recursive add");
            Assert.That(GetSvnStatus(testFile1), Is.Not.EqualTo(SvnStatus.Added), "Recursive add");
            Assert.That(GetSvnStatus(testFile2), Is.Not.EqualTo(SvnStatus.Added), "Recursive add");
        }
Exemplo n.º 27
0
        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);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 28
0
        public void TestAddWithParents()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            sbox.Create(SandBoxRepository.Empty);
            string dir = sbox.Wc;

            string file = Path.Combine(dir, "a/b/d/e/f");

            Directory.CreateDirectory(Path.Combine(dir, "a/b/d/e"));
            TouchFile(file);

            SvnAddArgs aa = new SvnAddArgs();
            aa.ThrowOnError = false;
            //aa.AddParents = true;
            Assert.That(Client.Add(file, aa), Is.False);

            aa.ThrowOnError = true;
            aa.AddParents = true;

            Assert.That(Client.Add(file, aa));

            Client.Info(file, delegate(object sender, SvnInfoEventArgs e)
            {
                // This check verifies Subversion 1.5 behavior, but will probably
                // give the real guid in 1.6+
                Assert.That(e.RepositoryId, Is.Not.EqualTo(Guid.Empty));
            });

            Guid gg;
            Assert.That(Client.TryGetRepositoryId(file, out gg));

            Assert.That(gg, Is.Not.EqualTo(Guid.Empty));
        }
Exemplo n.º 29
0
        public void Add_MultiLevelAdd()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            sbox.Create(SandBoxRepository.Empty);

            string subdir = Path.Combine(sbox.Wc, "trunk/a/b/c");
            Directory.CreateDirectory(Path.Combine(sbox.Wc, "trunk/a/b/c"));

            SvnAddArgs aa = new SvnAddArgs();
            aa.Force = true; // Continue
            aa.AddParents = true;

            Client.Add(subdir, aa);

            Client.Commit(sbox.Wc);
        }
Exemplo n.º 30
0
        public void Add_BasicAdd()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            sbox.Create(SandBoxRepository.Default);

            string dir = sbox.Wc;
            string testFile = Path.Combine(dir, "testfile.txt");

            File.WriteAllText(testFile, "This is a testfile");

            SvnAddArgs a = new SvnAddArgs();
            a.Depth = SvnDepth.Empty;

            Client.Add(testFile, a);

            // Check if the file is part of a working copy
            Guid g;
            Assert.That(Client.TryGetRepositoryId(testFile, out g));
            Assert.That(g, Is.Not.EqualTo(Guid.Empty));

            Collection<SvnStatusEventArgs> st;
            Client.GetStatus(testFile, out st);

            Assert.That(st.Count, Is.EqualTo(1));
            Assert.That(st[0].LocalNodeStatus, Is.EqualTo(SvnStatus.Added));

            Client.Configuration.LogMessageRequired = false;
            Assert.That(Client.Commit(dir));
        }
Exemplo n.º 31
0
        public void List_WorstLocalDir()
        {
            SvnSandBox sbox           = new SvnSandBox(this);
            Uri        CollabReposUri = sbox.CreateRepository(SandBoxRepository.MergeScenario);

            Uri    uri = CollabReposUri;
            string tmp = sbox.GetTempDir();

            Client.CheckOut(uri, tmp);

            string s1 = "start #";
            string s2 = "q!@#$%^&()_- +={}[]',.eia";
            string s3 = "done!";

            string d = tmp;

            Directory.CreateDirectory(d = Path.Combine(d, s1));
            Directory.CreateDirectory(d = Path.Combine(d, s2));
            Directory.CreateDirectory(d = Path.Combine(d, s3));

            string f1, f2;

            TouchFile(f1 = Path.Combine(d, "file.txt"));
            TouchFile(f2 = Path.Combine(d, s2 + ".txt"));

            SvnAddArgs aa = new SvnAddArgs();

            aa.AddParents = true;
            Client.Add(f1, aa);
            Client.Add(f2, aa);
            Client.Commit(tmp);

            SvnInfoEventArgs ea;

            Client.GetInfo(d, out ea);

            Uri r = new Uri(new Uri(new Uri(uri, SvnTools.PathToRelativeUri(s1 + "/")), SvnTools.PathToRelativeUri(s2 + "/")), SvnTools.PathToRelativeUri(s3 + "/"));

            if (Environment.Version.Major < 4)
            {
                Assert.That(r.ToString(), Is.EqualTo(ea.Uri.ToString()));
            }

            // Run with a .Net normalized Uri
            Client.List(r,
                        delegate(object sender, SvnListEventArgs e)
            {
                Assert.That(e.RepositoryRoot, Is.EqualTo(uri));
            });

            // Run with a SVN normalized Uri
            Client.List(ea.Uri,
                        delegate(object sender, SvnListEventArgs e)
            {
                Assert.That(e.RepositoryRoot, Is.EqualTo(uri));
            });

            r = new Uri(new Uri(new Uri(uri, SvnTools.PathToRelativeUri(s1 + "//")), SvnTools.PathToRelativeUri(s2 + "///")), SvnTools.PathToRelativeUri(s3 + "////"));

            // Run with uncanonical Uri
            Client.List(r,
                        delegate(object sender, SvnListEventArgs e)
            {
                Assert.That(e.RepositoryRoot, Is.EqualTo(uri));
            });
        }
Exemplo n.º 32
0
        public void List_WorstLocalDir()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            Uri CollabReposUri = sbox.CreateRepository(SandBoxRepository.MergeScenario);

            Uri uri = CollabReposUri;
            string tmp = sbox.GetTempDir();

            Client.CheckOut(uri, tmp);

            string s1 = "start #";
            string s2 = "q!@#$%^&()_- +={}[]',.eia";
            string s3  = "done!";

            string d = tmp;
            Directory.CreateDirectory(d = Path.Combine(d, s1));
            Directory.CreateDirectory(d = Path.Combine(d, s2));
            Directory.CreateDirectory(d = Path.Combine(d, s3));

            string f1, f2;
            TouchFile(f1 = Path.Combine(d, "file.txt"));
            TouchFile(f2 = Path.Combine(d, s2 + ".txt"));

            SvnAddArgs aa = new SvnAddArgs();
            aa.AddParents = true;
            Client.Add(f1, aa);
            Client.Add(f2, aa);
            Client.Commit(tmp);

            SvnInfoEventArgs ea;
            Client.GetInfo(d, out ea);

            Uri r = new Uri(new Uri(new Uri(uri, SvnTools.PathToRelativeUri(s1 + "/")), SvnTools.PathToRelativeUri(s2 + "/")), SvnTools.PathToRelativeUri(s3+"/"));

            if (Environment.Version.Major < 4)
                Assert.That(r.ToString(), Is.EqualTo(ea.Uri.ToString()));

            // Run with a .Net normalized Uri
            Client.List(r,
                delegate(object sender, SvnListEventArgs e)
                {
                    Assert.That(e.RepositoryRoot, Is.EqualTo(uri));
                });

            // Run with a SVN normalized Uri
            Client.List(ea.Uri,
                delegate(object sender, SvnListEventArgs e)
                {
                    Assert.That(e.RepositoryRoot, Is.EqualTo(uri));
                });

            r = new Uri(new Uri(new Uri(uri, SvnTools.PathToRelativeUri(s1 + "//")), SvnTools.PathToRelativeUri(s2 + "///")), SvnTools.PathToRelativeUri(s3 + "////"));

            // Run with uncanonical Uri
            Client.List(r,
                delegate(object sender, SvnListEventArgs e)
                {
                    Assert.That(e.RepositoryRoot, Is.EqualTo(uri));
                });
        }
Exemplo n.º 33
0
		public override void Add (FilePath path, bool recurse, IProgressMonitor monitor)
		{
			SvnAddArgs args = new SvnAddArgs ();
			BindMonitor (args, monitor);
			args.Depth = recurse ? SvnDepth.Infinity : SvnDepth.Empty;
			lock (client)
				client.Add (path, args);
		}
Exemplo n.º 34
0
        public override void OnExecute(CommandEventArgs e)
        {
            string         argumentFile = e.Argument as string;
            List <SvnItem> selection    = new List <SvnItem>();

            if (string.IsNullOrEmpty(argumentFile))
            {
                if (e.ShouldPrompt(true))
                {
                    selection.AddRange(e.Selection.GetSelectedSvnItems(true));

                    using (PendingChangeSelector pcs = new PendingChangeSelector())
                    {
                        pcs.Text = CommandStrings.AddDialogTitle;

                        pcs.PreserveWindowPlacement = true;

                        pcs.LoadItems(selection,
                                      delegate(SvnItem item) { return(!item.IsVersioned && item.IsVersionable); },
                                      delegate(SvnItem item)
                        {
                            if (item.IsIgnored)
                            {
                                return(false);
                            }
                            else if (item.IsSccExcluded)
                            {
                                return(false);
                            }
                            return(item.InSolution);
                        });

                        if (pcs.ShowDialog(e.Context) != DialogResult.OK)
                        {
                            return;
                        }

                        selection.Clear();
                        selection.AddRange(pcs.GetSelectedItems());
                    }
                }
                else
                {
                    foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true))
                    {
                        if (!item.IsVersioned && item.IsVersionable && !item.IsIgnored && item.InSolution)
                        {
                            selection.Add(item);
                        }
                    }
                }
            }
            else
            {
                selection.Add(e.GetService <ISvnStatusCache>()[argumentFile]);
            }

            ICollection <string>     paths           = SvnItem.GetPaths(selection);
            IAnkhOpenDocumentTracker documentTracker = e.GetService <IAnkhOpenDocumentTracker>();

            documentTracker.SaveDocuments(paths); // Make sure all files are saved before updating/merging!

            using (DocumentLock lck = documentTracker.LockDocuments(paths, DocumentLockType.NoReload))
                using (lck.MonitorChangesForReload())
                    e.GetService <IProgressRunner>().RunModal(CommandStrings.AddTaskDialogTitle,
                                                              delegate(object sender, ProgressWorkerArgs ee)
                    {
                        SvnAddArgs args = new SvnAddArgs();
                        args.Depth      = SvnDepth.Empty;
                        args.AddParents = true;

                        foreach (SvnItem item in selection)
                        {
                            ee.Client.Add(item.FullPath, args);
                        }
                    });
        }
Exemplo n.º 35
0
        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.");
                }
            }
        }
Exemplo n.º 36
0
        public void Copy()
        {
            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);

            SvnLogArgs logArgs = new SvnLogArgs();
            logArgs.StrictNodeHistory = true;
            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;
                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);
                }

                foreach (SvnChangeItem changeItem in changeItems.Values)
                {
                    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:
                            {
                                Console.WriteLine(" A {0}", targetPath);
                                SvnAddArgs svnAddArgs = new SvnAddArgs();
                                svnAddArgs.ThrowOnError = true;
                                svnAddArgs.Depth = SvnDepth.Empty;
                                _client.Add(targetPath, svnAddArgs);
                            }
                            break;
                        case SvnChangeAction.Delete:
                            {
                                Console.WriteLine(" D {0}", targetPath);
                                SvnDeleteArgs svnDeleteArgs = new SvnDeleteArgs();
                                svnDeleteArgs.ThrowOnError = true;
                                _client.Delete(targetPath, svnDeleteArgs);
                            }
                            break;
                    }
                }

                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("Commiting {0}", _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.");
                    }
                }

                _client.Commit(_args.Destination, commitArgs); 
            }
        }
Exemplo n.º 37
0
 public static bool Add(string path, SvnAddArgs args)
 {
     return(m_Client.Add(path, args));
 }
Exemplo n.º 38
0
        public override void OnExecute(CommandEventArgs e)
        {
            List <string>  toAdd = new List <string>();
            List <SvnItem> items = new List <SvnItem>();

            foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true))
            {
                if (item.IsVersioned)
                {
                    items.Add(item);
                }
                else if (item.IsFile && item.IsVersionable && item.InSolution && !item.IsIgnored && !item.IsSccExcluded)
                {
                    toAdd.Add(item.FullPath); // Add new files  ### Alternative: Show them as added
                    items.Add(item);
                }
            }

            if (items.Count == 0)
            {
                return;
            }

            SvnRevision start = SvnRevision.Base;
            SvnRevision end   = SvnRevision.Working;

            // should we show the path selector?
            if (e.ShouldPrompt(true))
            {
                using (CommonFileSelectorDialog dlg = new CommonFileSelectorDialog())
                {
                    dlg.Text          = CommandStrings.UnifiedDiffTitle;
                    dlg.Items         = items;
                    dlg.RevisionStart = start;
                    dlg.RevisionEnd   = end;

                    if (dlg.ShowDialog(e.Context) != DialogResult.OK)
                    {
                        return;
                    }

                    items.Clear();
                    items.AddRange(dlg.GetCheckedItems());
                    start = dlg.RevisionStart;
                    end   = dlg.RevisionEnd;
                }
            }

            if (items.Count == 0)
            {
                return;
            }

            SvnRevisionRange revRange = new SvnRevisionRange(start, end);

            IAnkhTempFileManager tempfiles = e.GetService <IAnkhTempFileManager>();
            string tempFile = tempfiles.GetTempFile(".patch");

            IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>();
            string slndir            = ss.ProjectRoot;

            using (MemoryStream stream = new MemoryStream())
            {
                e.Context.GetService <IProgressRunner>().RunModal(CommandStrings.RunningDiff,
                                                                  delegate(object sender, ProgressWorkerArgs ee)
                {
                    SvnAddArgs aa   = new SvnAddArgs();
                    aa.ThrowOnError = false;
                    aa.AddParents   = false;
                    foreach (string item in toAdd)
                    {
                        ee.Client.Add(item, aa);
                    }

                    SvnDiffArgs diffArgs    = new SvnDiffArgs();
                    diffArgs.IgnoreAncestry = true;
                    diffArgs.NoDeleted      = false;
                    diffArgs.ThrowOnError   = false;

                    foreach (SvnItem item in items)
                    {
                        SvnWorkingCopy wc;
                        if (!string.IsNullOrEmpty(slndir) && item.IsBelowPath(slndir))
                        {
                            diffArgs.RelativeToPath = slndir;
                        }
                        else if ((wc = item.WorkingCopy) != null)
                        {
                            diffArgs.RelativeToPath = wc.FullPath;
                        }
                        else
                        {
                            diffArgs.RelativeToPath = null;
                        }

                        if (!ee.Client.Diff(item.FullPath, revRange, diffArgs, stream))
                        {
                            if (diffArgs.LastException != null)
                            {
                                StreamWriter sw = new StreamWriter(stream);
                                sw.WriteLine();
                                sw.WriteLine(string.Format("# {0}: {1}", item.FullPath, diffArgs.LastException.Message));
                                sw.Flush();
                                // Don't dispose the writer as that might close the stream
                            }

                            if (diffArgs.IsLastInvocationCanceled)
                            {
                                break;
                            }
                        }
                    }

                    stream.Flush();
                });

                stream.Position = 0;
                using (StreamReader sr = new StreamReader(stream))
                {
                    File.WriteAllText(tempFile, sr.ReadToEnd(), Encoding.UTF8);
                    VsShellUtilities.OpenDocument(e.Context, tempFile);
                }
            }
        }
Exemplo n.º 39
0
		public override void Add (FilePath path, bool recurse, IProgressMonitor monitor)
		{
			var args = new SvnAddArgs {
				Depth = recurse ? SvnDepth.Infinity : SvnDepth.Empty,
			};
			BindMonitor (monitor);
			lock (client)
				client.Add (path, args);
		}
Exemplo n.º 40
0
 static void AddPathToSubversion(CommandEventArgs e, string path)
 {
     using (SvnClient cl = e.GetService<ISvnClientPool>().GetNoUIClient())
     {
         SvnAddArgs aa = new SvnAddArgs();
         aa.AddParents = true;
         cl.Add(path, aa);
     }
 }
Exemplo n.º 41
0
        /// <summary>
        /// Adds all files which are marked as to be added to subversion
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns></returns>
        private bool PreCommit_AddNewFiles(PendingCommitState state)
        {
            foreach (PendingChange pc in state.Changes)
            {
                if (pc.Change != null && pc.Change.State == PendingChangeKind.New)
                {
                    SvnItem item = pc.SvnItem;

                    // HACK: figure out why PendingChangeKind.New is still true
                    if (item.IsVersioned)
                        continue; // No need to add

                    SvnAddArgs a = new SvnAddArgs();
                    a.AddParents = true;
                    a.Depth = SvnDepth.Empty;
                    a.ThrowOnError = false;

                    if (!state.Client.Add(pc.FullPath, a))
                    {
                        if (a.LastException != null && a.LastException.SvnErrorCode == SvnErrorCode.SVN_ERR_WC_UNSUPPORTED_FORMAT)
                        {
                            state.MessageBox.Show(a.LastException.Message + Environment.NewLine + Environment.NewLine
                                + PccStrings.YouCanDownloadAnkh, "", MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                            return false;
                        }
                        else if (state.MessageBox.Show(a.LastException.Message, "", MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Error) == DialogResult.Cancel)
                            return false;
                    }
                }
            }
            return true;
        }
Exemplo n.º 42
0
        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.");
                }
            }
        }
Exemplo n.º 43
0
        public override void OnExecute(CommandEventArgs e)
        {
            string argumentFile = e.Argument as string;
            List<SvnItem> selection = new List<SvnItem>();

            if (string.IsNullOrEmpty(argumentFile))
            {
                if (e.PromptUser || (!e.DontPrompt && !Shift))
                {
                    selection.AddRange(e.Selection.GetSelectedSvnItems(true));

                    using (PendingChangeSelector pcs = new PendingChangeSelector())
                    {
                        pcs.Text = CommandStrings.AddDialogTitle;

                        pcs.PreserveWindowPlacement = true;

                        pcs.LoadItems(selection,
                                      delegate(SvnItem item) { return !item.IsVersioned && item.IsVersionable; },
                                      delegate(SvnItem item) { return !item.IsIgnored || !item.InSolution; });

                        if (pcs.ShowDialog(e.Context) != DialogResult.OK)
                            return;

                        selection.Clear();
                        selection.AddRange(pcs.GetSelectedItems());
                    }
                }
                else
                {
                    foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true))
                    {
                        if (!item.IsVersioned && item.IsVersionable && !item.IsIgnored && item.InSolution)
                            selection.Add(item);
                    }
                }
            }
            else
            {
                selection.Add(e.GetService<IFileStatusCache>()[argumentFile]);
            }

            ICollection<string> paths = SvnItem.GetPaths(selection);
            IAnkhOpenDocumentTracker documentTracker = e.GetService<IAnkhOpenDocumentTracker>();
            documentTracker.SaveDocuments(paths); // Make sure all files are saved before updating/merging!

            using (DocumentLock lck = documentTracker.LockDocuments(paths, DocumentLockType.NoReload))
            using (lck.MonitorChangesForReload())
                e.GetService<IProgressRunner>().RunModal(CommandStrings.AddTaskDialogTitle,
                    delegate(object sender, ProgressWorkerArgs ee)
                    {
                        SvnAddArgs args = new SvnAddArgs();
                        args.Depth = SvnDepth.Empty;
                        args.AddParents = true;

                        foreach (SvnItem item in selection)
                        {
                            ee.Client.Add(item.FullPath, args);
                        }
                    });
        }
Exemplo n.º 44
0
        public void Add_AddDirectoryNonRecursively()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            sbox.Create(SandBoxRepository.Empty);

            string dir1, dir2, testFile1, testFile2;
            CreateSubdirectories(sbox.Wc, out dir1, out dir2, out testFile1, out testFile2);

            this.Client.Notify += new EventHandler<SvnNotifyEventArgs>(this.NotifyCallback);
            SvnAddArgs a = new SvnAddArgs();
            a.Depth = SvnDepth.Empty;
            // do a non-recursive add here
            this.Client.Add(dir1, a);

            Assert.That(this.Notifications.Length == 1, "Too many or no notifications received. Added recursively?");
            Assert.That(this.GetSvnStatus(dir1), Is.EqualTo(SvnStatus.Added), "Subdirectory not added");

            Assert.That(GetSvnStatus(dir2), Is.Not.EqualTo(SvnStatus.Added), "Recursive add");
            Assert.That(GetSvnStatus(testFile1), Is.Not.EqualTo(SvnStatus.Added), "Recursive add");
            Assert.That(GetSvnStatus(testFile2), Is.Not.EqualTo(SvnStatus.Added), "Recursive add");
        }
Exemplo n.º 45
0
        internal void HandleEvent(AnkhCommand command)
        {
            List<SvnProject> dirtyProjects;
            HybridCollection<string> dirtyCheck;
            HybridCollection<string> maybeAdd;

            AnkhSccProvider provider = Context.GetService<AnkhSccProvider>();

            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 (SvnProject project in dirtyProjects)
                {
                    if (project.RawHandle == null)
                    {
                        if (project.IsSolution)
                            provider.UpdateSolutionGlyph();

                        continue; // All IVsSccProjects have a RawHandle
                    }

                    try
                    {
                        project.RawHandle.SccGlyphChanged(0, null, null, null);
                    }
                    catch { }
                }
            }

            if (maybeAdd != null)
                using (SvnClient cl = GetService<ISvnClientPool>().GetNoUIClient())
                {
                    foreach (string file in maybeAdd)
                    {
                        SvnItem item = Cache[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)
                        {
                            SvnAddArgs aa = new SvnAddArgs();
                            aa.ThrowOnError = false; // Just ignore errors here; make the user add them themselves
                            aa.AddParents = true;

                            cl.Add(item.FullPath, aa);
                        }
                    }
                }
        }
Exemplo n.º 46
0
        public void Add_AddDirectoryRecursively()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            sbox.Create(SandBoxRepository.Default);
            string WcPath = sbox.Wc;

            string dir1, dir2, testFile1, testFile2;
            CreateSubdirectories(WcPath, out dir1, out dir2, out testFile1, out testFile2);

            this.Client.Notify += new EventHandler<SvnNotifyEventArgs>(this.NotifyCallback);
            // now a recursive add
            SvnAddArgs a = new SvnAddArgs();
            a.Depth = SvnDepth.Infinity;
            this.Client.Add(dir1, a);

            // enough notifications?
            Assert.That(this.Notifications.Length, Is.EqualTo(4), "Received wrong number of notifications");
            Assert.That(this.GetSvnStatus(dir1), Is.EqualTo(SvnStatus.Added), "Subdirectory not added");
            Assert.That(this.GetSvnStatus(dir2), Is.EqualTo(SvnStatus.Added), "Subsubdirectory not added");
            Assert.That(this.GetSvnStatus(testFile1), Is.EqualTo(SvnStatus.Added), "File in subdirectory not added");
            Assert.That(this.GetSvnStatus(testFile2), Is.EqualTo(SvnStatus.Added), "File in subsubdirectory not added");
        }
Exemplo n.º 47
0
        public void Add_AddFileWithNonAsciiFilename()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            sbox.Create(SandBoxRepository.Default);
            string WcPath = sbox.Wc;
            SvnAddArgs a = new SvnAddArgs();
            a.Depth = SvnDepth.Infinity;

            string newFile = Path.Combine(WcPath, "eia.");
            File.Create(newFile).Close();
            this.Client.Add(newFile, a);
        }
Exemplo n.º 48
0
        public void Add_AddWithForce()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            sbox.Create(SandBoxRepository.Default);
            string WcPath = sbox.Wc;

            SvnAddArgs a = new SvnAddArgs();
            a.Depth = SvnDepth.Empty;

            string file = Path.Combine(WcPath, "AssemblyInfo.cs");
            TouchFile(file);
            this.Client.Add(file);
            try
            {
                this.Client.Add(file, a);
                Assert.Fail("Should have failed");
            }
            catch (SvnException)
            {
                // swallow
            }

            // should not fail
            a.Force = true;
            this.Client.Add(file, a);
        }
Exemplo n.º 49
0
        private void Commit(string alias, string svnFolder, string revFolder)
        {
            var reviFiles = System.IO.Directory.GetFiles(revFolder, "*.*", System.IO.SearchOption.AllDirectories);
            var svnFiles  = System.IO.Directory.GetFiles(svnFolder, "*.*", System.IO.SearchOption.AllDirectories);

            Dictionary <string, string> reviFileIndex = new Dictionary <string, string>();
            Dictionary <string, string> svnFileIndex  = new Dictionary <string, string>();

            string url         = Url.TrimEnd('/') + "/" + alias;
            string tempFolder  = TempFolderPath(alias);
            bool   workingCopy = false;


            if (Directory.Exists(Path.Combine(tempFolder, ".svn")))
            {
                workingCopy = true;
            }
            else if (!Directory.Exists(tempFolder))
            {
                Directory.CreateDirectory(tempFolder);
            }


            foreach (string s in reviFiles)
            {
                DirectoryInfo parent = Directory.GetParent(s);
                if (!parent.Name.StartsWith("."))
                {
                    reviFileIndex.Add(s.Substring(revFolder.Length).Trim('\\'), s);
                }
            }


            foreach (string s in svnFiles)
            {
                if (!s.ToLower().Contains(".svn"))
                {
                    svnFileIndex.Add(s.Substring(svnFolder.Length).Trim('\\'), s);
                }
            }

            using (SvnClient client = new SvnClient())
            {
                client.LoadConfiguration("path");
                client.Authentication.DefaultCredentials = new NetworkCredential(Login, Password);

                if (!workingCopy)
                {
                    client.Add(tempFolder);
                }

                SvnUriTarget target = new SvnUriTarget(url);

                //remove not needed files
                foreach (var key in svnFileIndex.Keys)
                {
                    if (!reviFileIndex.ContainsKey(key))
                    {
                        client.Delete(svnFileIndex[key]);
                    }
                }


                //add missing files
                foreach (var file in reviFileIndex)
                {
                    string newPath = Path.Combine(svnFolder, file.Key);
                    bool   add     = false;

                    if (!File.Exists(newPath))
                    {
                        add = true;
                        ensureDirectory(Directory.GetParent(newPath).FullName, false);
                    }

                    System.IO.File.Copy(file.Value, Path.Combine(svnFolder, file.Key), true);
                }

                SvnAddArgs saa = new SvnAddArgs();
                saa.Force = true;
                saa.Depth = SvnDepth.Infinity;


                foreach (var dir in Directory.GetDirectories(svnFolder))
                {
                    if (!dir.Contains(".svn"))
                    {
                        client.Add(dir, saa);
                    }
                }

                SvnCommitArgs args = new SvnCommitArgs();
                args.LogMessage    = "Comitted from Courier 2";
                args.ThrowOnError  = true;
                args.ThrowOnCancel = true;

                client.Commit(tempFolder, args);
            }
        }
Exemplo n.º 50
0
 public static bool Add(string path, SvnAddArgs args)
 {
     return m_Client.Add(path, args);
 }