示例#1
0
        internal bool DeleteBranch(SvnListEventArgs selectedBranch)
        {
            try
            {
                if (selectedBranch != null)
                {
                    using (SvnClient client = new SvnClient())
                    {
                        // Bind the SharpSvn UI to our client for SSL certificate and credentials
                        SvnUIBindArgs bindArgs = new SvnUIBindArgs();
                        SvnUI.Bind(client, bindArgs);

                        SvnDeleteArgs arg = new SvnDeleteArgs();
                        arg.LogMessage = "ADMIN-0: Branch Deleted";

                        return(client.RemoteDelete(selectedBranch.Uri, arg));
                    }
                }
                return(false);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#2
0
        public void Delete_ForceDelete()
        {
            SvnSandBox sbox = new SvnSandBox(this);

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

            string path = Path.Combine(WcPath, "Form.cs");

            // modify the file
            using (StreamWriter writer = new StreamWriter(path, true))
            {
                writer.WriteLine("Hi ho");
            }

            // this will throw if force doesn't work
            SvnDeleteArgs a = new SvnDeleteArgs();

            a.ThrowOnError = false;

            Assert.That(Client.Delete(path, a), Is.False);

            a.ThrowOnError = true;
            a.Force        = true;

            Assert.That(Client.Delete(path, a), Is.True, "Delete failed");
        }
示例#3
0
        public static bool Delete(SvnClient client, string srcUrl)
        {
            SvnDeleteArgs args = new SvnDeleteArgs();

            args.LogMessage = "";
            return(client.RemoteDelete(new Uri(srcUrl), args));
        }
示例#4
0
        public override void Delete(FilePath path, bool force, IProgressMonitor monitor)
        {
            SvnDeleteArgs args = new SvnDeleteArgs();

            BindMonitor(args, monitor);
            args.Force = force;
            client.Delete(path, args);
        }
        public override void OnExecute(CommandEventArgs e)
        {
            List <SvnOrigin>          items   = new List <SvnOrigin>();
            List <ISvnRepositoryItem> refresh = new List <ISvnRepositoryItem>();

            foreach (ISvnRepositoryItem i in e.Selection.GetSelection <ISvnRepositoryItem>())
            {
                if (i.Origin == null || i.Origin.Target.Revision != SvnRevision.Head || i.Origin.IsRepositoryRoot)
                {
                    break;
                }

                items.Add(i.Origin);
                refresh.Add(i);
            }

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

            string logMessage;

            Uri[] uris;
            using (ConfirmDeleteDialog d = new ConfirmDeleteDialog())
            {
                d.Context = e.Context;
                d.SetUris(items);

                if (!e.DontPrompt && d.ShowDialog(e.Context) != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                logMessage = d.LogMessage;
                uris       = d.Uris;
            }

            try
            {
                e.GetService <IProgressRunner>().RunModal(CommandStrings.Deleting,
                                                          delegate(object sender, ProgressWorkerArgs a)
                {
                    SvnDeleteArgs da = new SvnDeleteArgs();
                    da.LogMessage    = logMessage;

                    a.Client.RemoteDelete(uris, da);
                });
            }
            finally
            {
                // TODO: Don't refresh each item; refresh each parent!
                foreach (ISvnRepositoryItem r in refresh)
                {
                    r.RefreshItem(true);
                }
            }
        }
示例#6
0
        public override void Delete(FilePath path, bool force, IProgressMonitor monitor)
        {
            var args = new SvnDeleteArgs {
                Force = force,
            };

            BindMonitor(monitor);
            lock (client)
                client.Delete(path, args);
        }
示例#7
0
        /// <summary>
        /// Force removal of a path.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="isFolder"></param>
        public void ForceRemove(string path, bool isFolder)
        {
            SvnDeleteArgs deleteArgs = new SvnDeleteArgs();

            deleteArgs.Force = true;
            this.svnClient.Delete(path, deleteArgs);
            if (isFolder)
            {
                this.svnClient.Update(path);
            }
        }
示例#8
0
        public void DeleteClosedFeature()
        {
            string featureRootUrl = string.Empty;

            Info(SvnTarget.FromString(WorkingCopyPath), (sender, args) => featureRootUrl = args.Uri.ToString());
            var svnDeleteArgs = new SvnDeleteArgs {
                LogMessage = "Remove closed feature branch"
            };

            RemoteDelete(new Uri(featureRootUrl), svnDeleteArgs);
        }
示例#9
0
        protected override void ExecuteSVNTask(SvnClient client)
        {
            SvnCommitResult result;
            SvnDeleteArgs args = new SvnDeleteArgs();

            args.LogMessage = Message;
            args.ThrowOnError = true;

            Log(Level.Info, Resources.SVNDelete, SvnUri);

            client.RemoteDelete(svnUri, args, out result);
        }
        public override void OnExecute(CommandEventArgs e)
        {
            List<SvnOrigin> items = new List<SvnOrigin>();
            List<ISvnRepositoryItem> refresh = new List<ISvnRepositoryItem>();
            foreach (ISvnRepositoryItem i in e.Selection.GetSelection<ISvnRepositoryItem>())
            {
                if (i.Origin == null || i.Origin.Target.Revision != SvnRevision.Head || i.Origin.IsRepositoryRoot)
                    break;

                items.Add(i.Origin);
                refresh.Add(i);
            }

            if(items.Count == 0)
                return;

            string logMessage;
            Uri[] uris;
            using(ConfirmDeleteDialog d = new ConfirmDeleteDialog())
            {
                d.Context = e.Context;
                d.SetUris(items);

                if (!e.DontPrompt && d.ShowDialog(e.Context) != System.Windows.Forms.DialogResult.OK)
                    return;

                logMessage = d.LogMessage;
                uris = d.Uris;
            }

            try
            {
                e.GetService<IProgressRunner>().RunModal("Deleting",
                    delegate(object sender, ProgressWorkerArgs a)
                    {
                        SvnDeleteArgs da = new SvnDeleteArgs();
                        da.LogMessage = logMessage;

                        a.Client.RemoteDelete(uris, da);
                    });
            }
            finally
            {
                // TODO: Don't refresh each item; refresh each parent!
                foreach(ISvnRepositoryItem r in refresh)
                {
                    r.RefreshItem(true);
                }
            }
        }
示例#11
0
        public void Add_AddAndDelete()
        {
            SvnSandBox sbox = new SvnSandBox(this);

            sbox.Create(SandBoxRepository.Default);

            Uri    uri = sbox.RepositoryUri;
            string dir = sbox.Wc;

            string file = Path.Combine(dir, "test.txt");

            TouchFile(file);
            Client.Add(file);

            SvnDeleteArgs da = new SvnDeleteArgs();

            da.Force = true;

            Client.Delete(file, da);
            Assert.That(!File.Exists(file));

            file += ".2";

            TouchFile(file);
            Client.Add(file);

            File.Delete(file);
            Assert.That(!File.Exists(file));

            da.ThrowOnError = false; // This throws an error in 1.5 but succeeds anyway
            Assert.That(Client.Delete(file, da), "This should succeed in 1.7+");

            file += ".3";

            TouchFile(file);
            Client.Add(file);

            File.Delete(file);
            Assert.That(!File.Exists(file));

            da.ThrowOnError = true; // This works in 1.5
            da.KeepLocal    = true;
            Client.Delete(file, da);

            Client.Status(dir,
                          delegate(object sender, SvnStatusEventArgs e)
            {
                Assert.Fail("Nothing modified");
            });
        }
示例#12
0
        public bool MetaDelete(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            SvnDeleteArgs da = new SvnDeleteArgs();

            da.ThrowOnError = false;
            da.Force        = true;
            da.KeepLocal    = true;

            return(Client.Delete(path, da));
        }
示例#13
0
        public void Add_AddAndDelete()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            sbox.Create(SandBoxRepository.Default);

            Uri uri = sbox.RepositoryUri;
            string dir = sbox.Wc;

            string file = Path.Combine(dir, "test.txt");
            TouchFile(file);
            Client.Add(file);

            SvnDeleteArgs da = new SvnDeleteArgs();
            da.Force = true;

            Client.Delete(file, da);
            Assert.That(!File.Exists(file));

            file += ".2";

            TouchFile(file);
            Client.Add(file);

            File.Delete(file);
            Assert.That(!File.Exists(file));

            da.ThrowOnError = false; // This throws an error in 1.5 but succeeds anyway
            Assert.That(Client.Delete(file, da), "This should succeed in 1.7+");

            file += ".3";

            TouchFile(file);
            Client.Add(file);

            File.Delete(file);
            Assert.That(!File.Exists(file));

            da.ThrowOnError = true; // This works in 1.5
            da.KeepLocal = true;
            Client.Delete(file, da);

            Client.Status(dir,
            delegate(object sender, SvnStatusEventArgs e)
            {
                Assert.Fail("Nothing modified");
            });
        }
示例#14
0
        public bool SvnDelete(string path)
        {
            return(DoWithSvn(path, svnClient => {
                svnClient.Authentication.DefaultCredentials = _svnCredentials;
                var args = new SvnDeleteArgs {
                    Force = true,
                    KeepLocal = false,
                    LogMessage = string.Format("Deleted by SvnAutoCommitter service via SharpSvn. {0}", path)
                };
                var result = svnClient.Delete(path, args);
                if (result)
                {
                    _logger.InfoFormat("SharpSvn has deleted {0}", path);
                }

                return result;
            }));
        }
示例#15
0
        public void Delete_TestDeleteFromRepos()
        {
            SvnSandBox sbox     = new SvnSandBox(this);
            Uri        ReposUrl = sbox.CreateRepository(SandBoxRepository.AnkhSvnCases);
            Uri        path1    = new Uri(ReposUrl, "trunk/doc");
            Uri        path2    = new Uri(ReposUrl, "trunk/Form.cs");

            SvnCommitResult ci;
            SvnDeleteArgs   a = new SvnDeleteArgs();

            Assert.That(Client.RemoteDelete(new Uri[] { path1, path2 }, a, out ci));

            String cmd = this.RunCommand("svn", "list " + ReposUrl);

            Assert.That(cmd.IndexOf("doc") == -1, "Directory wasn't deleted ");
            Assert.That(cmd.IndexOf("Form.cs") == -1, "Directory wasn't deleted");

            Assert.That(ci, Is.Not.Null, "CommitInfo is invalid");
        }
示例#16
0
        public bool SvnDelete(string path)
        {
            return(DoWithSvn(path, svnClient => {
                svnClient.Authentication.DefaultCredentials = _svnCredentials;
                var args = new SvnDeleteArgs
                {
                    Force = true,
                    KeepLocal = false,
                    LogMessage = $"Deleted by FilesWatcher service via SharpSvn. {path}"
                };
                var result = svnClient.Delete(path, args);
                if (result)
                {
                    Log.ShowLog($"SharpSvn has deleted {path}");
                }

                return result;
            }));
        }
示例#17
0
        public void Delete_WCFiles()
        {
            SvnSandBox sbox = new SvnSandBox(this);

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

            string path1 = Path.Combine(WcPath, "Form.cs");
            string path2 = Path.Combine(WcPath, "AssemblyInfo.cs");

            SvnDeleteArgs a = new SvnDeleteArgs();

            Assert.That(Client.Delete(new string[] { path1, path2 }, a));

            Assert.That(!File.Exists(path1), "File not deleted");
            Assert.That(!File.Exists(path2), "File not deleted");

            Assert.That(this.GetSvnStatus(path1), Is.EqualTo(SvnStatus.Deleted), "File not deleted");
            Assert.That(this.GetSvnStatus(path2), Is.EqualTo(SvnStatus.Deleted), "File not deleted");

            Assert.That(Client.Commit(WcPath));
        }
示例#18
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);
                }
            }
        }
示例#19
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);
            }
        }
示例#20
0
文件: FsCopy.cs 项目: ainiaa/svn2svn
        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);
                }                
            }
        }
示例#21
0
		public override void Delete (FilePath path, bool force, IProgressMonitor monitor)
		{
			var args = new SvnDeleteArgs {
				Force = force,
			};
			BindMonitor (monitor);
			lock (client) 
				client.Delete (path, args);
		}
示例#22
0
        public Task Synchronize(bool update = true)
        {
            return(Task.Factory.StartNew(() =>
            {
                ExecuteSvnClient(client =>
                {
                    try
                    {
                        if (!Directory.Exists(Paths.MainDirPath) ||
                            !Directory.Exists(Path.Combine(Paths.MainDirPath, ".svn")))
                        {
                            client.CheckOut(new SvnUriTarget(new Uri(SettingsInfo.RepoAddress)), Paths.MainDirPath);
                        }

                        if (update)
                        {
                            client.Update(Paths.MainDirPath);
                        }
                    }
                    catch (SvnRepositoryIOException ex)
                    {
                        if (ex.InnerException != null &&
                            ex.InnerException.GetType() == typeof(SvnAuthenticationException))
                        {
                            throw new Exception(
                                "Dane logowania do repozytorium plików są nieprawidłowe. Proszę sprawdzić ustawienia");
                        }

                        throw;
                    }

                    if (!Directory.Exists(Paths.RecordsPath))
                    {
                        Directory.CreateDirectory(Paths.RecordsPath);
                    }
                    if (!Directory.Exists(Paths.TemplatesPath))
                    {
                        Directory.CreateDirectory(Paths.TemplatesPath);
                    }

                    client.GetStatus(Paths.MainDirPath, out var changedFiles);

                    foreach (var svnStatusEventArgse in changedFiles)
                    {
                        if (svnStatusEventArgse.LocalContentStatus == SvnStatus.Missing ||
                            svnStatusEventArgse.LocalContentStatus == SvnStatus.Deleted)
                        {
                            if (File.Exists(svnStatusEventArgse.Path) || Directory.Exists(svnStatusEventArgse.Path))
                            {
                                var delArgs = new SvnDeleteArgs {
                                    KeepLocal = true
                                };
                                client.Delete(svnStatusEventArgse.Path, delArgs);
                            }
                            else
                            {
                                client.Delete(svnStatusEventArgse.Path);
                            }
                        }

                        if (svnStatusEventArgse.LocalContentStatus == SvnStatus.NotVersioned)
                        {
                            client.Add(svnStatusEventArgse.Path);
                        }

                        if (svnStatusEventArgse.LocalContentStatus == SvnStatus.Conflicted)
                        {
                            client.Resolve(svnStatusEventArgse.Path, SvnAccept.MineFull);
                        }
                    }

                    var ca = new SvnCommitArgs {
                        LogMessage = "Synchronizacja obiektów inwentaryzacji"
                    };

                    if (changedFiles.Any())
                    {
                        client.Commit(Paths.MainDirPath, ca);
                    }
                });
            }));
        }
示例#23
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.");
                }
            }
        }
示例#24
0
        public override void OnExecute(CommandEventArgs e)
        {
            ISvnRepositoryItem item = EnumTools.GetSingle(e.Selection.GetSelection <ISvnRepositoryItem>());

            if (item == null)
            {
                return;
            }

            string          copyTo;
            bool            copyBelow     = false;
            bool            suggestExport = false;
            ISvnStatusCache cache         = e.GetService <ISvnStatusCache>();

            if (item.NodeKind == SharpSvn.SvnNodeKind.Directory)
            {
                using (FolderBrowserDialog fd = new FolderBrowserDialog())
                {
                    fd.ShowNewFolderButton = false;

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

                    copyTo    = fd.SelectedPath;
                    copyBelow = true;

                    SvnItem dirItem = cache[copyTo];

                    if (dirItem == null || !dirItem.IsVersioned)
                    {
                        suggestExport = true;
                    }
                }
            }
            else
            {
                using (SaveFileDialog sfd = new SaveFileDialog())
                {
                    sfd.CheckPathExists = true;
                    sfd.OverwritePrompt = true;
                    string name = item.Origin.Target.FileName;
                    string ext  = Path.GetExtension(item.Origin.Target.FileName);
                    sfd.Filter   = string.Format("{0} files|*.{0}|All files (*.*)|*", ext.TrimStart('.'));
                    sfd.FileName = name;

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

                    copyTo = SvnTools.GetNormalizedFullPath(sfd.FileName);

                    SvnItem fileItem = cache[copyTo];

                    if (File.Exists(copyTo))
                    {
                        // We prompted to confirm; remove the file!

                        if (fileItem.IsVersioned)
                        {
                            e.GetService <IProgressRunner>().RunModal(CommandStrings.Copying,
                                                                      delegate(object sender, ProgressWorkerArgs a)
                            {
                                SvnDeleteArgs da = new SvnDeleteArgs();
                                da.Force         = true;
                                a.Client.Delete(copyTo, da);
                            });
                        }
                        else
                        {
                            SvnItem.DeleteNode(copyTo);
                        }
                    }

                    SvnItem dir = fileItem.Parent;

                    if (dir == null || !(dir.IsVersioned && dir.IsVersionable))
                    {
                        suggestExport = true;
                    }
                }
            }

            if (!suggestExport)
            {
                e.GetService <IProgressRunner>().RunModal(CommandStrings.Copying,
                                                          delegate(object sender, ProgressWorkerArgs a)
                {
                    SvnCopyArgs ca   = new SvnCopyArgs();
                    ca.CreateParents = true;
                    if (copyBelow)
                    {
                        ca.AlwaysCopyAsChild = true;
                    }

                    a.Client.Copy(item.Origin.Target, copyTo, ca);
                });
            }
            else
            {
                AnkhMessageBox mb = new AnkhMessageBox(e.Context);

                if (DialogResult.Yes == mb.Show(CommandStrings.NotInWorkingCopyExportInstead,
                                                CommandStrings.NotInWorkingCopyTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                {
                    e.GetService <IProgressRunner>().RunModal(CommandStrings.Exporting,
                                                              delegate(object sender, ProgressWorkerArgs a)
                    {
                        SvnExportArgs ea = new SvnExportArgs();
                        ea.Revision      = item.Revision;
                        ea.Overwrite     = true;

                        a.Client.Export(item.Origin.Target, copyTo, ea);
                    });
                }
            }
        }
示例#25
0
        public override void OnExecute(CommandEventArgs e)
        {
            ISvnRepositoryItem item = EnumTools.GetSingle(e.Selection.GetSelection<ISvnRepositoryItem>());

            if (item == null)
                return;

            string copyTo;
            bool copyBelow = false;
            bool suggestExport = false;
            IFileStatusCache cache = e.GetService<IFileStatusCache>();

            if (item.NodeKind == SharpSvn.SvnNodeKind.Directory)
            {
                using (FolderBrowserDialog fd = new FolderBrowserDialog())
                {
                    fd.ShowNewFolderButton = false;

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

                    copyTo = fd.SelectedPath;
                    copyBelow = true;

                    SvnItem dirItem = cache[copyTo];

                    if (dirItem == null || !dirItem.IsVersioned)
                        suggestExport = true;
                }
            }
            else
            {
                using (SaveFileDialog sfd = new SaveFileDialog())
                {
                    sfd.CheckPathExists = true;
                    sfd.OverwritePrompt = true;
                    string name = item.Origin.Target.FileName;
                    string ext = Path.GetExtension(item.Origin.Target.FileName);
                    sfd.Filter = string.Format("{0} files|*.{0}|All files (*.*)|*", ext.TrimStart('.'));
                    sfd.FileName = name;

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

                    copyTo = SvnTools.GetNormalizedFullPath(sfd.FileName);

                    SvnItem fileItem = cache[copyTo];

                    if (File.Exists(copyTo))
                    {
                        // We prompted to confirm; remove the file!

                        if (fileItem.IsVersioned)
                            e.GetService<IProgressRunner>().RunModal("Copying",
                                delegate(object sender, ProgressWorkerArgs a)
                                {
                                    SvnDeleteArgs da = new SvnDeleteArgs();
                                    da.Force = true;
                                    a.Client.Delete(copyTo, da);
                                });
                        else
                            File.Delete(copyTo);
                    }

                    SvnItem dir = fileItem.Parent;

                    if (dir == null || !(dir.IsVersioned && dir.IsVersionable))
                        suggestExport = true;
                }
            }

            if (!suggestExport)
            {
                e.GetService<IProgressRunner>().RunModal("Copying",
                    delegate(object sender, ProgressWorkerArgs a)
                    {
                        SvnCopyArgs ca = new SvnCopyArgs();
                        ca.CreateParents = true;
                        if (copyBelow)
                            ca.AlwaysCopyAsChild = true;

                        a.Client.Copy(item.Origin.Target, copyTo, ca);
                    });
            }
            else
            {
                AnkhMessageBox mb = new AnkhMessageBox(e.Context);

                if (DialogResult.Yes == mb.Show("The specified path is not in a workingcopy; would you like to export the file instead?",
                    "No Working Copy", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                {
                    e.GetService<IProgressRunner>().RunModal("Exporting",
                    delegate(object sender, ProgressWorkerArgs a)
                    {
                        SvnExportArgs ea = new SvnExportArgs();
                        ea.Revision = item.Revision;

                        a.Client.Export(item.Origin.Target, copyTo, ea);
                    });
                }
            }
        }
示例#26
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);
            }
        }
示例#27
0
        /// <summary>
        /// Fixes up missing files by fixing their casing or deleting them
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns></returns>
        private bool PreCommit_HandleMissingFiles(PendingCommitState state)
        {
            foreach (string path in new List<string>(state.CommitPaths))
            {
                SvnItem item = state.Cache[path];

                if (item.Status.LocalContentStatus != SvnStatus.Missing)
                    continue;

                if (item.IsCasingConflicted)
                {
                    string correctCasing = GetSvnCasing(item);
                    string actualCasing = SvnTools.GetTruePath(item.FullPath);

                    if (correctCasing == null || actualCasing == null || !string.Equals(correctCasing, actualCasing, StringComparison.OrdinalIgnoreCase))
                        continue; // Nothing to fix here :(

                    string correctFile = Path.GetFileName(correctCasing);
                    string actualFile = Path.GetFileName(actualCasing);

                    if (correctFile == actualFile)
                        continue; // Casing issue is not in the file; can't fix :(

                    IAnkhOpenDocumentTracker odt = GetService<IAnkhOpenDocumentTracker>();
                    using (odt.LockDocument(correctCasing, DocumentLockType.NoReload))
                    using (odt.LockDocument(actualCasing, DocumentLockType.NoReload))
                    {
                        try
                        {
                            File.Move(actualCasing, correctCasing);

                            // Fix the name in the commit list
                            state.CommitPaths[state.CommitPaths.IndexOf(path)] = actualCasing;
                        }
                        catch
                        { }
                        finally
                        {
                            item.MarkDirty();
                            GetService<IFileStatusMonitor>().ScheduleGlyphUpdate(item.FullPath);
                        }
                    }
                }
                else if (!item.Exists)
                {
                    SvnDeleteArgs da = new SvnDeleteArgs();
                    da.KeepLocal = true;
                    da.ThrowOnError = false;

                    if (!state.Client.Delete(path, da))
                    {
                        state.MessageBox.Show(da.LastException.Message, "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        return false;
                    }
                }
            }

            return true;
        }
示例#28
0
        public void Delete_TestDeleteFromRepos()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            Uri ReposUrl = sbox.CreateRepository(SandBoxRepository.AnkhSvnCases);
            Uri path1 = new Uri(ReposUrl, "trunk/doc");
            Uri path2 = new Uri(ReposUrl, "trunk/Form.cs");

            SvnCommitResult ci;
            SvnDeleteArgs a = new SvnDeleteArgs();

            Assert.That(Client.RemoteDelete(new Uri[] { path1, path2 }, a, out ci));

            String cmd = this.RunCommand("svn", "list " + ReposUrl);
            Assert.That(cmd.IndexOf("doc") == -1, "Directory wasn't deleted ");
            Assert.That(cmd.IndexOf("Form.cs") == -1, "Directory wasn't deleted");

            Assert.That(ci, Is.Not.Null, "CommitInfo is invalid");
        }
示例#29
0
文件: SvnCopy.cs 项目: ainiaa/svn2svn
        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.");
                }
            }
        }
示例#30
0
        public void MoreStatusTestsObsolete()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            sbox.Create(SandBoxRepository.AnkhSvnCases, false);
            string WcPath = sbox.Wc;
            Uri ReposUrl = sbox.RepositoryUri;

            using (SvnClient client = NewSvnClient(true, false))
            {
                client.Update(WcPath);
                client.CreateDirectory(Path.Combine(WcPath, "statTst"));
                string local = Path.Combine(WcPath, "statTst/LocalStatBase1");
                string local2 = Path.Combine(WcPath, "statTst/LocalStatBase2");
                string local3 = Path.Combine(WcPath, "statTst/LocalStatBase3");
                string local4 = Path.Combine(WcPath, "statTst/LocalStatBase4");
                string local5 = Path.Combine(WcPath, "statTst/LocalStatBase5");
                string local6 = Path.Combine(WcPath, "statTst/LocalStatBase6");

                SvnCommitResult ci, ci9;

                Touch2(local);
                client.Add(local);
                client.Commit(WcPath, out ci);

                client.Copy(local, local2);
                client.Commit(WcPath);

                client.SetProperty(local, "test-q", "value");

                client.Copy(local, local3);
                client.Copy(local, local6);
                client.Copy(local, local5);
                client.Commit(WcPath, out ci9);

                client.Copy(local, local4);
                client.Delete(local5);

                client.SetProperty(local, "test-q", "value2");
                client.RemoteDelete(new Uri(ReposUrl, "statTst/LocalStatBase2"));
                client.AddToChangeList(local6, "MyList");
                Touch2(local6);

                Guid reposGuid;

                client.TryGetRepositoryId(ReposUrl, out reposGuid);

                for (int mode = 0; mode < 4; mode++)
                {
                    SvnStatusArgs a = new SvnStatusArgs();

                    a.RetrieveRemoteStatus = mode % 2 == 1;
                    a.RetrieveAllEntries = mode > 1;

                    int n = 0;

                    client.Status(Path.Combine(WcPath, "statTst"), a, delegate(object sender, SvnStatusEventArgs e)
                    {
                        n++;
                        string p = e.Path;
                        int nn = -1;
                        switch (e.Path[e.Path.Length - 1])
                        {
                            case '1':
                                nn = 1;
                                break;
                            case '2':
                                nn = 2;
                                break;
                            case '3':
                                nn = 3;
                                break;
                            case '4':
                                nn = 4;
                                break;
                            case '5':
                                nn = 5;
                                break;
                            case '6':
                                nn = 6;
                                break;
                            default:
                                Assert.That(e.FullPath, Is.EqualTo(Path.GetDirectoryName(local)));
                                break;
                        }

                        if (nn >= 0)
                            Assert.That(Path.GetDirectoryName(e.FullPath), Is.EqualTo(Path.Combine(WcPath, "statTst")));
                        Assert.That(Path.GetFileName(e.Path), Is.EqualTo(Path.GetFileName(e.FullPath)));

                        switch (nn)
                        {
                            case 1:
                                Assert.That(e.LocalNodeStatus, Is.EqualTo(SvnStatus.Modified));
                                Assert.That(e.LocalTextStatus, Is.EqualTo(SvnStatus.Normal));
                                Assert.That(e.LocalPropertyStatus, Is.EqualTo(SvnStatus.Modified));
                                break;
                            case 2:
                                Assert.That(e.LocalNodeStatus, Is.EqualTo(SvnStatus.Normal));
                                Assert.That(e.LocalTextStatus, Is.EqualTo(SvnStatus.Normal));
                                Assert.That(e.LocalPropertyStatus, Is.EqualTo(SvnStatus.None));
                                break;
                            case 3:
                                Assert.That(e.LocalNodeStatus, Is.EqualTo(SvnStatus.Normal));
                                Assert.That(e.LocalTextStatus, Is.EqualTo(SvnStatus.Normal));
                                Assert.That(e.LocalPropertyStatus, Is.EqualTo(SvnStatus.Normal));
                                break;
                            case 4:
                                Assert.That(e.LocalNodeStatus, Is.EqualTo(SvnStatus.Added));
                                Assert.That(e.LocalTextStatus, Is.EqualTo(SvnStatus.Normal));
                                Assert.That(e.LocalPropertyStatus, Is.EqualTo(SvnStatus.Normal));
                                break;
                            case 5:
                                Assert.That(e.LocalNodeStatus, Is.EqualTo(SvnStatus.Deleted));
                                Assert.That(e.LocalTextStatus, Is.EqualTo(SvnStatus.Normal));
                                Assert.That(e.LocalPropertyStatus, Is.EqualTo(SvnStatus.None));
                                break;
                            case 6:
                                Assert.That(e.LocalNodeStatus, Is.EqualTo(SvnStatus.Modified));
                                Assert.That(e.LocalTextStatus, Is.EqualTo(SvnStatus.Modified));
                                Assert.That(e.LocalPropertyStatus, Is.EqualTo(SvnStatus.Normal));
                                break;
                            default:
                                break;
                        }

                        Assert.That(e.LocalCopied, Is.EqualTo(nn == 4));
                        Assert.That(e.Wedged, Is.False);
                        if (a.RetrieveRemoteStatus)
                        {
                            Assert.That(e.RemoteContentStatus, Is.EqualTo(nn == 2 ? SvnStatus.Deleted : SvnStatus.None));
                        }
                        else
                        {
                            Assert.That(e.RemoteContentStatus, Is.EqualTo(SvnStatus.None));
                        }

                        Assert.That(e.RemoteLock, Is.Null);
                        Assert.That(e.RemotePropertyStatus, Is.EqualTo(SvnStatus.None));

                        if (nn == 2 && a.RetrieveRemoteStatus)
                        {
                            Assert.That(e.RemoteUpdateCommitAuthor, Is.Null);
                            Assert.That(e.RemoteUpdateNodeKind, Is.EqualTo(SvnNodeKind.File));
                            Assert.That(e.RemoteUpdateCommitTime, Is.EqualTo(DateTime.MinValue));
                            Assert.That(e.RemoteUpdateRevision, Is.EqualTo(ci.Revision + 3));
                        }
                        else if (nn == -1 && a.RetrieveRemoteStatus)
                        {
                            Assert.That(e.RemoteUpdateCommitAuthor, Is.EqualTo(Environment.UserName));
                            Assert.That(e.RemoteUpdateNodeKind, Is.EqualTo(SvnNodeKind.Directory));
                            Assert.That(e.RemoteUpdateCommitTime, Is.GreaterThan(DateTime.UtcNow - new TimeSpan(0, 45, 0)));
                            Assert.That(e.RemoteUpdateRevision, Is.EqualTo(ci.Revision + 3));
                        }
                        else
                        {
                            Assert.That(e.RemoteUpdateCommitAuthor, Is.Null);
                            Assert.That(e.RemoteUpdateNodeKind, Is.EqualTo(SvnNodeKind.None));
                            Assert.That(e.RemoteUpdateCommitTime, Is.EqualTo(DateTime.MinValue));
                            Assert.That(e.RemoteUpdateRevision, Is.LessThan(0L));
                        }
                        Assert.That(e.Switched, Is.False);
                        if (nn >= 0)
                            Assert.That(e.Uri, Is.EqualTo(new Uri(ReposUrl, "statTst/localStatBase" + nn.ToString())));
                        else
                            Assert.That(e.Uri, Is.EqualTo(new Uri(ReposUrl, "statTst/")));

                        Assert.That(e.WorkingCopyInfo, Is.Not.Null);

                        if (nn >= 0)
                            Assert.That(e.WorkingCopyInfo.Name, Is.EqualTo(Path.GetFileName(e.Path)));
                        else
                            Assert.That(e.WorkingCopyInfo.Name, Is.EqualTo(""));

                        Assert.That(e.WorkingCopyInfo.ChangeList, Is.EqualTo((nn == 6) ? "MyList" : null));
                        if (nn >= 0)
                            Assert.That(e.WorkingCopyInfo.Checksum, Is.Not.Null);

                        Assert.That(e.WorkingCopyInfo.Uri, Is.EqualTo(e.Uri));
                        Assert.That(e.WorkingCopyInfo.RepositoryUri, Is.EqualTo(ReposUrl));
                        /*if(a.ContactRepository)
                            Assert.That(e.WorkingCopyInfo.RepositoryId, Is.EqualTo(reposGuid));
                        else*/

                        Assert.That(e.WorkingCopyInfo.RepositoryId, Is.Not.EqualTo(Guid.Empty), "Expected guid for {0} / nn={1}", e.Path, nn);

                        Assert.That(e.WorkingCopyInfo.IsAbsent, Is.False);
                        Assert.That(e.WorkingCopyInfo.IsDeleted, Is.False);
                        Assert.That(e.WorkingCopyInfo.IsIncomplete, Is.False);

                        //
                        Assert.That(e.WorkingCopyInfo.ConflictNewFile, Is.Null);
                        Assert.That(e.WorkingCopyInfo.ConflictOldFile, Is.Null);
                        Assert.That(e.WorkingCopyInfo.ConflictWorkFile, Is.Null);

                        if (nn == 4)
                        {
                            Assert.That(e.WorkingCopyInfo.IsCopy, Is.True);
                            Assert.That(e.WorkingCopyInfo.CopiedFrom, Is.EqualTo(new Uri(ReposUrl, "statTst/localStatBase1")));
                            Assert.That(e.WorkingCopyInfo.LastChangeAuthor, Is.Not.Null);
                            Assert.That(e.WorkingCopyInfo.CopiedFromRevision, Is.EqualTo(ci.Revision + 2));
                        }
                        else
                        {
                            Assert.That(e.WorkingCopyInfo.IsCopy, Is.False);
                            Assert.That(e.WorkingCopyInfo.CopiedFrom, Is.Null);
                            Assert.That(e.WorkingCopyInfo.LastChangeAuthor, Is.EqualTo(Environment.UserName));
                            Assert.That(e.WorkingCopyInfo.CopiedFromRevision, Is.EqualTo(-1L));
                        }

                        Assert.That(e.WorkingCopyInfo.Depth, Is.EqualTo(SvnDepth.Infinity));
                        Assert.That(e.WorkingCopyInfo.HasProperties, Is.EqualTo(nn >= 0 && nn != 2));
                        Assert.That(e.WorkingCopyInfo.HasPropertyChanges, Is.EqualTo(nn == 1), "Expected property changes (nn={0})", nn);
                        Assert.That(e.WorkingCopyInfo.KeepLocal, Is.False);

                        if (nn == 4)
                        {
                            Assert.That(e.WorkingCopyInfo.LastChangeRevision, Is.EqualTo(9));
                            Assert.That(e.WorkingCopyInfo.LastChangeTime, Is.GreaterThan(DateTime.MinValue));
                            Assert.That(e.WorkingCopyInfo.Schedule, Is.EqualTo(SvnSchedule.Add));
                            Assert.That(e.WorkingCopyInfo.ContentChangeTime, Is.GreaterThan(DateTime.MinValue));
                            Assert.That(e.WorkingCopyInfo.Revision, Is.EqualTo(ci.Revision));
                            Assert.That(e.WorkingCopyInfo.WorkingCopySize, Is.EqualTo(36));
                        }
                        else
                        {
                            switch (nn)
                            {
                                case 2:
                                    Assert.That(e.WorkingCopyInfo.LastChangeRevision, Is.EqualTo(ci.Revision + 1));
                                    Assert.That(e.WorkingCopyInfo.Revision, Is.EqualTo(ci.Revision + 1));
                                    break;
                                default:
                                    Assert.That(e.WorkingCopyInfo.LastChangeRevision, Is.EqualTo((nn >= 0) ? (ci.Revision + 2) : ci.Revision));
                                    Assert.That(e.WorkingCopyInfo.Revision, Is.EqualTo((nn >= 0) ? (ci.Revision + 2) : ci.Revision));
                                    break;
                            }

                            Assert.That(e.WorkingCopyInfo.LastChangeTime, Is.GreaterThan(DateTime.UtcNow - new TimeSpan(0, 0, 45)));
                            Assert.That(e.WorkingCopyInfo.Schedule, Is.EqualTo((nn == 5) ? SvnSchedule.Delete : SvnSchedule.Normal));

                            if (nn == 5)
                            {
                                // Deleted node
                            }
                            else if (nn >= 0)
                            {
                                Assert.That(e.WorkingCopyInfo.ContentChangeTime, Is.GreaterThan(DateTime.UtcNow - new TimeSpan(0, 0, 45)));
                                Assert.That(e.WorkingCopyInfo.WorkingCopySize, Is.EqualTo(36L), "WCSize = 36");
                            }
                            else
                            {
                                Assert.That(e.WorkingCopyInfo.NodeKind, Is.EqualTo(SvnNodeKind.Directory));
                                Assert.That(e.WorkingCopyInfo.ContentChangeTime, Is.EqualTo(DateTime.MinValue));
                                Assert.That(e.WorkingCopyInfo.WorkingCopySize, Is.EqualTo(-1L), "WCSize = -1");
                            }
                        }
                        Assert.That(e.WorkingCopyInfo.LockComment, Is.Null);
                        Assert.That(e.WorkingCopyInfo.LockOwner, Is.Null);
                        Assert.That(e.WorkingCopyInfo.LockTime, Is.EqualTo(DateTime.MinValue));
                        Assert.That(e.WorkingCopyInfo.LockToken, Is.Null);
                        Assert.That(e.WorkingCopyInfo.NodeKind, Is.EqualTo(nn >= 0 ? SvnNodeKind.File : SvnNodeKind.Directory));
                        Assert.That(e.WorkingCopyInfo.PropertyRejectFile, Is.Null);
                    });

                    if (a.RetrieveAllEntries)
                        Assert.That(n, Is.EqualTo(7));
                    else if (a.RetrieveRemoteStatus)
                        Assert.That(n, Is.EqualTo(5));
                    else
                        Assert.That(n, Is.EqualTo(4));
                }

                File.Delete(local);

                client.Status(local, delegate(object sender, SvnStatusEventArgs e)
                {
                    Assert.That(e.WorkingCopyInfo.IsAbsent, Is.False);
                    Assert.That(e.WorkingCopyInfo.IsIncomplete, Is.False);
                    Assert.That(e.WorkingCopyInfo.IsDeleted, Is.False);
                    Assert.That(e.LocalContentStatus, Is.EqualTo(SvnStatus.Missing));
                });
                SvnDeleteArgs da = new SvnDeleteArgs();
                da.Force = true;
                client.Delete(local, da);
                client.Status(local, delegate(object sender, SvnStatusEventArgs e)
                {
                    Assert.That(e.WorkingCopyInfo.IsAbsent, Is.False);
                    Assert.That(e.WorkingCopyInfo.IsIncomplete, Is.False);
                    Assert.That(e.WorkingCopyInfo.IsDeleted, Is.False);
                    Assert.That(e.LocalContentStatus, Is.EqualTo(SvnStatus.Deleted));
                });

            }
        }
示例#31
0
        public void Delete_WCFiles()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            sbox.Create(SandBoxRepository.AnkhSvnCases);
            string WcPath = sbox.Wc;

            string path1 = Path.Combine(WcPath, "Form.cs");
            string path2 = Path.Combine(WcPath, "AssemblyInfo.cs");

            SvnDeleteArgs a = new SvnDeleteArgs();

            Assert.That(Client.Delete(new string[] { path1, path2 }, a));

            Assert.That(!File.Exists(path1), "File not deleted");
            Assert.That(!File.Exists(path2), "File not deleted");

            Assert.That(this.GetSvnStatus(path1), Is.EqualTo(SvnStatus.Deleted), "File not deleted");
            Assert.That(this.GetSvnStatus(path2), Is.EqualTo(SvnStatus.Deleted), "File not deleted");

            Assert.That(Client.Commit(WcPath));
        }
示例#32
0
        public void Delete_ForceDelete()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            sbox.Create(SandBoxRepository.AnkhSvnCases);
            string WcPath = sbox.Wc;

            string path = Path.Combine(WcPath, "Form.cs");

            // modify the file
            using (StreamWriter writer = new StreamWriter(path, true))
            {
                writer.WriteLine("Hi ho");
            }

            // this will throw if force doesn't work
            SvnDeleteArgs a = new SvnDeleteArgs();
            a.ThrowOnError = false;

            Assert.That(Client.Delete(path, a), Is.False);

            a.ThrowOnError = true;
            a.Force = true;

            Assert.That(Client.Delete(path, a), Is.True, "Delete failed");
        }
示例#33
0
		public override void Delete (FilePath path, bool force, IProgressMonitor monitor)
		{
			SvnDeleteArgs args = new SvnDeleteArgs ();
			BindMonitor (args, monitor);
			args.Force = force;
			lock (client) 
				client.Delete (path, args);
		}
示例#34
0
        public static void CompleteSync(Parameters parameters)
        {
            using (var client = new SharpSvn.SvnClient())
            {
                SetUpClient(parameters, client);

                if (parameters.UpdateBeforeCompleteSync)
                {
                    DebugMessage(parameters, "Updating");
                    client.Update(parameters.Path);
                    DebugMessage(parameters, "Done");
                }

                Collection <SvnStatusEventArgs> changedFiles;
                DebugMessage(parameters, "Getting status");
                client.GetStatus(parameters.Path, out changedFiles);
                DebugMessage(parameters, "Done");
                if (changedFiles.Count == 0)
                {
                    Console.WriteLine("No changes to commit.");
                    return;
                }

                //delete files from subversion that are not in filesystem
                //add files to subversion that are new in filesystem
                //modified files are automatically included as part of the commit

                //TODO: check remoteStatus
                DebugMessage(parameters, "Recording changes");
                foreach (var changedFile in changedFiles)
                {
                    if (changedFile.LocalContentStatus == SvnStatus.Missing)
                    {
                        // SVN thinks file is missing but it still exists hence
                        // a change in the case of the filename.
                        if (File.Exists(changedFile.Path))
                        {
                            var changedArgs = new SvnDeleteArgs {
                                KeepLocal = true
                            };
                            client.Delete(changedFile.Path, changedArgs);
                        }
                        else
                        {
                            client.Delete(changedFile.Path);
                        }
                    }
                    if (changedFile.LocalContentStatus == SvnStatus.NotVersioned)
                    {
                        client.Add(changedFile.Path);
                    }
                }
                DebugMessage(parameters, "Done");

                var ca = new SvnCommitArgs {
                    LogMessage = parameters.Message
                };
                SvnCommitResult result;
                DebugMessage(parameters, "Committing");
                if (client.Commit(parameters.Path, ca, out result))
                {
                    DebugMessage(parameters, "Done");
                    if (result == null)
                    {
                        Console.WriteLine("No result returned from commit.");
                        return;
                    }
                    if (!string.IsNullOrEmpty(result.PostCommitError))
                    {
                        Console.WriteLine("Post-commit hook error: " + result.PostCommitError);
                        return;
                    }
                    Console.WriteLine("Committed r" + result.Revision);
                }
                else
                {
                    if (result != null && !string.IsNullOrEmpty(result.PostCommitError))
                    {
                        Console.WriteLine("Post-commit hook error after failed commit: " + result.PostCommitError);
                        return;
                    }
                    Console.WriteLine("Commit failed.");
                }
            }
        }
示例#35
0
        public static void CompleteSync(Parameters parameters)
        {
            using (var client = new SharpSvn.SvnClient())
            {
                SetUpClient(parameters, client);

                if (parameters.UpdateBeforeCompleteSync)
                {
                    DebugMessage(parameters, "Updating");
                    client.Update(parameters.Path);
                    DebugMessage(parameters, "Done");
                }

                Collection<SvnStatusEventArgs> changedFiles;
                DebugMessage(parameters, "Getting status");
                client.GetStatus(parameters.Path, out changedFiles);
                DebugMessage(parameters, "Done");
                if(changedFiles.Count == 0)
                {
                    Console.WriteLine("No changes to commit.");
                    return;
                }

                //delete files from subversion that are not in filesystem
                //add files to subversion that are new in filesystem
                //modified files are automatically included as part of the commit

                //TODO: check remoteStatus
                DebugMessage(parameters, "Recording changes");
                foreach (var changedFile in changedFiles)
                {
                    if (changedFile.LocalContentStatus == SvnStatus.Missing)
                    {
                        // SVN thinks file is missing but it still exists hence
                        // a change in the case of the filename.
                        if (File.Exists(changedFile.Path))
                        {
                            var changedArgs = new SvnDeleteArgs {KeepLocal = true};
                            client.Delete(changedFile.Path, changedArgs);
                        }
                        else
                            client.Delete(changedFile.Path);
                    }
                    if (changedFile.LocalContentStatus == SvnStatus.NotVersioned)
                    {
                        client.Add(changedFile.Path);
                    }
                }
                DebugMessage(parameters, "Done");

                var ca = new SvnCommitArgs {LogMessage = parameters.Message};
                SvnCommitResult result;
                DebugMessage(parameters, "Committing");
                if (client.Commit(parameters.Path, ca, out result))
                {
                    DebugMessage(parameters, "Done");
                    if(result == null)
                    {
                        Console.WriteLine("No result returned from commit.");
                        return;
                    }
                    if (!string.IsNullOrEmpty(result.PostCommitError))
                    {
                        Console.WriteLine("Post-commit hook error: " + result.PostCommitError);
                        return;
                    }
                    Console.WriteLine("Committed r" + result.Revision);
                }
                else
                {
                    if (result != null && !string.IsNullOrEmpty(result.PostCommitError))
                    {
                        Console.WriteLine("Post-commit hook error after failed commit: " + result.PostCommitError);
                        return;
                    }
                    Console.WriteLine("Commit failed.");
                }
            }
        }
示例#36
0
文件: SvnCopy.cs 项目: ainiaa/svn2svn
        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); 
            }
        }
示例#37
0
        public override void OnExecute(CommandEventArgs e)
        {
            List <SvnItem> toDelete = new List <SvnItem>(e.Selection.GetSelectedSvnItems(true));

            AnkhMessageBox mb = new AnkhMessageBox(e.Context);

            string body;

            // We do as if we are Visual Studio here: Same texts, same behavior (same chance on data loss)
            if (toDelete.Count == 1)
            {
                body = string.Format(CommandStrings.XWillBeDeletedPermanently, toDelete[0].Name);
            }
            else
            {
                body = CommandStrings.TheSelectedItemsWillBeDeletedPermanently;
            }

            if (DialogResult.OK != mb.Show(body, "", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation))
            {
                return; // No delete
            }
            int hr = VSErr.S_OK;

            foreach (SvnItem item in toDelete)
            {
                {
                    IVsUIHierarchy hier;
                    uint           id;
                    IVsWindowFrame frame;

                    if (VsShellUtilities.IsDocumentOpen(e.Context, item.FullPath, Guid.Empty, out hier, out id, out frame))
                    {
                        hr = frame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave);
                        if (!VSErr.Succeeded(hr))
                        {
                            break; // Show error and cancel further actions
                        }
                    }
                }

                try
                {
                    if (item.IsVersioned)
                    {
                        using (SvnClient cl = e.GetService <ISvnClientPool>().GetNoUIClient())
                        {
                            SvnDeleteArgs da = new SvnDeleteArgs();
                            da.Force = true;
                            cl.Delete(item.FullPath, da);
                        }
                    }
                    else
                    {
                        SvnItem.DeleteNode(item.FullPath);
                    }
                }
                finally
                {
                    // TODO: Notify the working copy explorer here!
                    // (Maybe via one of these methods below)

                    e.GetService <ISvnStatusCache>().MarkDirtyRecursive(item.FullPath);
                    e.GetService <IFileStatusMonitor>().ScheduleGlyphUpdate(item.FullPath);
                }

                // Ok, now remove the file from projects

                IProjectFileMapper pfm = e.GetService <IProjectFileMapper>();

                List <SccProject> projects = new List <SccProject>(pfm.GetAllProjectsContaining(item.FullPath));

                foreach (SccProject p in projects)
                {
                    IVsProject2 p2 = p.RawHandle as IVsProject2;

                    if (p2 == null)
                    {
                        continue;
                    }

                    VSDOCUMENTPRIORITY[] prio = new VSDOCUMENTPRIORITY[1];
                    int  found;
                    uint id;
                    if (!VSErr.Succeeded(p2.IsDocumentInProject(item.FullPath, out found, prio, out id)) || found == 0)
                    {
                        continue; // Probably already removed (mapping out of synch?)
                    }
                    hr = p2.RemoveItem(0, id, out found);

                    if (!VSErr.Succeeded(hr))
                    {
                        break;
                    }
                }
            }

            if (!VSErr.Succeeded(hr))
            {
                mb.Show(Marshal.GetExceptionForHR(hr).Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#38
0
        public override void OnExecute(CommandEventArgs e)
        {
            List<SvnItem> toDelete = new List<SvnItem>(e.Selection.GetSelectedSvnItems(true));

            AnkhMessageBox mb = new AnkhMessageBox(e.Context);

            string body;

            // We do as if we are Visual Studio here: Same texts, same behavior (same chance on data loss)
            if (toDelete.Count == 1)
                body = string.Format(CommandStrings.XWillBeDeletedPermanently, toDelete[0].Name);
            else
                body = CommandStrings.TheSelectedItemsWillBeDeletedPermanently;

            if (DialogResult.OK != mb.Show(body, "", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation))
                return; // No delete

            int hr = VSConstants.S_OK;
            foreach (SvnItem item in toDelete)
            {
                {
                    IVsUIHierarchy hier;
                    uint id;
                    IVsWindowFrame frame;

                    if (VsShellUtilities.IsDocumentOpen(e.Context, item.FullPath, Guid.Empty, out hier, out id, out frame))
                    {
                        hr = frame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave);
                        if (!ErrorHandler.Succeeded(hr))
                            break; // Show error and cancel further actions
                    }
                }

                try
                {
                    if (item.IsVersioned)
                    {
                        using (SvnClient cl = e.GetService<ISvnClientPool>().GetNoUIClient())
                        {
                            SvnDeleteArgs da = new SvnDeleteArgs();
                            da.Force = true;
                            cl.Delete(item.FullPath, da);
                        }
                    }
                    else if (item.IsFile)
                        File.Delete(item.FullPath);
                    else if (item.IsDirectory)
                        Directory.Delete(item.FullPath, true); // Recursive delete!!
                }
                finally
                {
                    // TODO: Notify the working copy explorer here!
                    // (Maybe via one of these methods below)

                    e.GetService<IFileStatusCache>().MarkDirtyRecursive(item.FullPath);
                    e.GetService<IFileStatusMonitor>().ScheduleGlyphUpdate(item.FullPath);
                }

                // Ok, now remove the file from projects

                IProjectFileMapper pfm = e.GetService<IProjectFileMapper>();

                List<SvnProject> projects = new List<SvnProject>(pfm.GetAllProjectsContaining(item.FullPath));

                foreach (SvnProject p in projects)
                {
                    IVsProject2 p2 = p.RawHandle as IVsProject2;

                    if (p2 == null)
                        continue;

                    VSDOCUMENTPRIORITY[] prio = new VSDOCUMENTPRIORITY[1];
                    int found;
                    uint id;
                    if (!ErrorHandler.Succeeded(p2.IsDocumentInProject(item.FullPath, out found, prio, out id)) || found == 0)
                        continue; // Probably already removed (mapping out of synch?)

                    hr = p2.RemoveItem(0, id, out found);

                    if (!ErrorHandler.Succeeded(hr))
                        break;
                }
            }

            if (!ErrorHandler.Succeeded(hr))
                mb.Show(Marshal.GetExceptionForHR(hr).Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
示例#39
0
        /// <summary>
        /// Fixes up missing files by fixing their casing or deleting them
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns></returns>
        private bool PreCommit_HandleMissingFiles(PendingCommitState state)
        {
            foreach (string path in new List <string>(state.CommitPaths))
            {
                SvnItem item = state.Cache[path];

                if (item.Status.LocalNodeStatus != SvnStatus.Missing)
                {
                    continue;
                }

                if (item.IsCasingConflicted)
                {
                    string correctCasing = GetSvnCasing(item);
                    string actualCasing  = SvnTools.GetTruePath(item.FullPath);

                    if (correctCasing == null || actualCasing == null || !string.Equals(correctCasing, actualCasing, StringComparison.OrdinalIgnoreCase))
                    {
                        continue; // Nothing to fix here :(
                    }
                    string correctFile = Path.GetFileName(correctCasing);
                    string actualFile  = Path.GetFileName(actualCasing);

                    if (correctFile == actualFile)
                    {
                        continue; // Casing issue is not in the file; can't fix :(
                    }
                    IAnkhOpenDocumentTracker odt = GetService <IAnkhOpenDocumentTracker>();
                    using (odt.LockDocument(correctCasing, DocumentLockType.NoReload))
                        using (odt.LockDocument(actualCasing, DocumentLockType.NoReload))
                        {
                            try
                            {
                                File.Move(actualCasing, correctCasing);

                                // Fix the name in the commit list
                                state.CommitPaths[state.CommitPaths.IndexOf(path)] = actualCasing;
                            }
                            catch
                            { }
                            finally
                            {
                                item.MarkDirty();
                                GetService <IFileStatusMonitor>().ScheduleGlyphUpdate(item.FullPath);
                            }
                        }
                }
                else if (!item.Exists)
                {
                    SvnDeleteArgs da = new SvnDeleteArgs();
                    da.KeepLocal    = true;
                    da.ThrowOnError = false;

                    if (!state.Client.Delete(path, da))
                    {
                        state.MessageBox.Show(da.LastException.Message, "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        return(false);
                    }
                }
            }

            return(true);
        }