Example #1
0
        public void Diff_LocalDiff()
        {
            SvnSandBox sbox = new SvnSandBox(this);

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

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


            using (StreamWriter w = new StreamWriter(form, false))
                w.Write("Moo moo moo moo moo\r\nmon\r\nmooo moo moo \r\nssdgo");

            //Necessary to fix up headers

            string clientDiff = this.RunCommand("svn", "diff \"" + form + "\"");

            MemoryStream outstream = new MemoryStream();
            MemoryStream errstream = new MemoryStream();

            SvnDiffArgs a = new SvnDiffArgs();

            a.ErrorStream = errstream;
            this.Client.Diff(
                new SvnPathTarget(form, SvnRevision.Base),
                new SvnPathTarget(form, SvnRevision.Working),
                a, outstream);

            string err = Encoding.Default.GetString(errstream.ToArray());

            Assert.That(err, Is.EqualTo(""), "Error in diff: " + err);
            string apiDiff = Encoding.Default.GetString(outstream.ToArray());

            Assert.That(apiDiff, Is.EqualTo(clientDiff), "Client diff differs");
        }
Example #2
0
        public void Diff_ReposDiff()
        {
            SvnSandBox sbox       = new SvnSandBox(this);
            Uri        ReposUrl   = sbox.CreateRepository(SandBoxRepository.AnkhSvnCases);
            string     clientDiff = this.RunCommand("svn", "diff -r 1:5 " + ReposUrl);

            MemoryStream outstream = new MemoryStream();
            MemoryStream errstream = new MemoryStream();

            SvnDiffArgs a = new SvnDiffArgs();

            a.ErrorStream = errstream;
            Client.Diff(ReposUrl, new SvnRevisionRange(1, 5), a, outstream);

            string err = Encoding.Default.GetString(errstream.ToArray());

            Assert.That(err, Is.EqualTo(string.Empty), "Error in diff: " + err);

            string apiDiff = Encoding.Default.GetString(outstream.ToArray());

            string[] clientLines = clientDiff.Split('\n');
            string[] apiLines    = apiDiff.Split('\n');
            Array.Sort <string>(clientLines);
            Array.Sort <string>(apiLines);

            Assert.That(apiLines, Is.EqualTo(clientLines), "Diffs differ");
        }
Example #3
0
        private string Diff(string pSourcePath, Uri u)
        {
            if (client == null)
            {
                Init();
            }
            try
            {
                MemoryStream objMemoryStream = new MemoryStream();
                SvnDiffArgs  da = new SvnDiffArgs();
                da.IgnoreAncestry = true;
                da.DiffArguments.Add("-b");
                da.DiffArguments.Add("-w");

                bool b = client.Diff(SvnTarget.FromString(pSourcePath), new SvnUriTarget(u, SvnRevision.Head), da, objMemoryStream);
                objMemoryStream.Position = 0;
                StreamReader strReader = new StreamReader(objMemoryStream);
                string       str       = strReader.ReadToEnd();
                return(str);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #4
0
        public void Diff_DiffBinary()
        {
            SvnSandBox sbox = new SvnSandBox(this);

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

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

            this.RunCommand("svn", "propset svn:mime-type application/octet-stream " +
                            path);
            this.RunCommand("svn", "ci -m '' " + path);

            using (StreamWriter w = new StreamWriter(path))
                w.WriteLine("Hi there");


            MemoryStream outstream = new MemoryStream();
            MemoryStream errstream = new MemoryStream();

            SvnDiffArgs a = new SvnDiffArgs();

            a.ErrorStream = errstream;

            // this should not diff a binary file
            Assert.That(Client.Diff(
                            path,
                            new SvnRevisionRange(SvnRevision.Base, SvnRevision.Working),
                            a,
                            outstream));

            string diff = Encoding.ASCII.GetString(outstream.ToArray());

            Assert.That(diff.IndexOf("application/octet-stream") >= 0);


            outstream           = new MemoryStream();
            errstream           = new MemoryStream();
            a                   = new SvnDiffArgs();
            a.ErrorStream       = errstream;
            a.IgnoreContentType = true;

            this.Client.Diff(
                path,
                new SvnRevisionRange(SvnRevision.Base, SvnRevision.Working),
                a,
                outstream);

            Assert.That(outstream.Length > 0);
            diff = Encoding.ASCII.GetString(outstream.ToArray());
            Assert.That(diff.IndexOf("application/octet-stream") < 0);
        }
Example #5
0
        public override void OnExecute(CommandEventArgs e)
        {
            PathSelectorResult result = ShowDialog(e);
            if (!result.Succeeded)
                return;

            SvnRevisionRange revRange = new SvnRevisionRange(result.RevisionStart, result.RevisionEnd);

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

            IAnkhSolutionSettings ss = e.GetService<IAnkhSolutionSettings>();
            string slndir = ss.ProjectRoot;
            string slndirP = slndir + "\\";

            SvnDiffArgs args = new SvnDiffArgs();
            args.IgnoreAncestry = true;
            args.NoDeleted = false;
            args.Depth = result.Depth;

            using (MemoryStream stream = new MemoryStream())
            {
                e.Context.GetService<IProgressRunner>().RunModal("Diffing",
                    delegate(object sender, ProgressWorkerArgs ee)
                    {
                        foreach (SvnItem item in result.Selection)
                        {
                            SvnWorkingCopy wc;
                            if (!string.IsNullOrEmpty(slndir) &&
                                item.FullPath.StartsWith(slndirP, StringComparison.OrdinalIgnoreCase))
                                args.RelativeToPath = slndir;
                            else if ((wc = item.WorkingCopy) != null)
                                args.RelativeToPath = wc.FullPath;
                            else
                                args.RelativeToPath = null;

                            ee.Client.Diff(item.FullPath, revRange, args, stream);
                        }

                        stream.Flush();
                        stream.Position = 0;
                    });
                using (StreamReader sr = new StreamReader(stream))
                {
                    File.WriteAllText(tempFile, sr.ReadToEnd(), Encoding.UTF8);
                    VsShellUtilities.OpenDocument(e.Context, tempFile);
                }
            }
        }
Example #6
0
        public override string GetUnifiedDiff(FilePath path1, SvnRevision revision1, FilePath path2, SvnRevision revision2, bool recursive)
        {
            SvnPathTarget t1   = new SvnPathTarget(path1, GetRevision(revision1));
            SvnPathTarget t2   = new SvnPathTarget(path2, GetRevision(revision2));
            SvnDiffArgs   args = new SvnDiffArgs();

            args.Depth = recursive ? SvnDepth.Infinity : SvnDepth.Children;
            MemoryStream ms = new MemoryStream();

            client.Diff(t1, t2, args, ms);
            ms.Position = 0;
            using (StreamReader sr = new StreamReader(ms)) {
                return(sr.ReadToEnd());
            }
        }
Example #7
0
        public void Diff_DiffBinary()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            sbox.Create(SandBoxRepository.AnkhSvnCases);
            string WcPath = sbox.Wc;

            string path = Path.Combine(WcPath, "Form.cs");
            this.RunCommand("svn", "propset svn:mime-type application/octet-stream " +
                path);
            this.RunCommand("svn", "ci -m '' " + path);

            using (StreamWriter w = new StreamWriter(path))
                w.WriteLine("Hi there");

            MemoryStream outstream = new MemoryStream();
            MemoryStream errstream = new MemoryStream();

            SvnDiffArgs a = new SvnDiffArgs();
            a.ErrorStream = errstream;

            // this should not diff a binary file
            Assert.That(Client.Diff(
                path,
                new SvnRevisionRange(SvnRevision.Base, SvnRevision.Working),
                a,
                outstream));

            string diff = Encoding.ASCII.GetString(outstream.ToArray());
            Assert.That(diff.IndexOf("application/octet-stream") >= 0);

            outstream = new MemoryStream();
            errstream = new MemoryStream();
            a = new SvnDiffArgs();
            a.ErrorStream = errstream;
            a.IgnoreContentType = true;

            this.Client.Diff(
                path,
                new SvnRevisionRange(SvnRevision.Base, SvnRevision.Working),
                a,
                outstream);

            Assert.That(outstream.Length > 0);
            diff = Encoding.ASCII.GetString(outstream.ToArray());
            Assert.That(diff.IndexOf("application/octet-stream") < 0);
        }
Example #8
0
        private string Diff(string pSourcePath, Uri u)
        {
            if (client == null)
            {
                Init();
            }

            // avoid running commands in parallel so just wait for last commands to finish or timeout after 10 seconds
            int i = 0;

            while (client.IsCommandRunning && i < 100)
            {
                Thread.Sleep(100);
                i++;
            }


            try
            {
                MemoryStream objMemoryStream = new MemoryStream();
                SvnDiffArgs  da = new SvnDiffArgs();
                da.IgnoreAncestry = true;
                da.DiffArguments.Add("-b");
                da.DiffArguments.Add("-w");

                bool b = client.Diff(SvnTarget.FromString(pSourcePath), new SvnUriTarget(u, SvnRevision.Head), da, objMemoryStream);
                objMemoryStream.Position = 0;
                StreamReader strReader = new StreamReader(objMemoryStream);
                string       str       = strReader.ReadToEnd();
                return(str);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #9
0
		public override string GetUnifiedDiff (FilePath path1, SvnRevision revision1, FilePath path2, SvnRevision revision2, bool recursive)
		{
			SvnPathTarget t1 = new SvnPathTarget (path1, GetRevision (revision1));
			SvnPathTarget t2 = new SvnPathTarget (path2, GetRevision (revision2));
			SvnDiffArgs args = new SvnDiffArgs ();
			args.Depth = recursive ? SvnDepth.Infinity : SvnDepth.Children;
			MemoryStream ms = new MemoryStream ();
			lock (client) 
				client.Diff (t1, t2, args, ms);
			ms.Position = 0;
			using (StreamReader sr = new StreamReader (ms)) {
				return sr.ReadToEnd ();
			}
		}
Example #10
0
        public static void Diff_ReposDiff(string[] args, long Rev1, long Rev2)
        {
            //string clientDiff = this.RunCommand("svn", "diff -r 1:5 " + this.ReposUrl);

            MemoryStream outstream = new MemoryStream();
            MemoryStream errstream = new MemoryStream();

            SvnDiffArgs a = new SvnDiffArgs();

            Parameters parameters;

            if (!Parameters.TryParse(args, out parameters))
            {
                return;
            }

            using (var client = new SharpSvn.SvnClient())
            {
                SetUpClient(parameters, client);

                var target = SvnTarget.FromString(parameters.Path);
                SvnInfoEventArgs svnInfoEventArgs;
                SvnUpdateResult  svnUpdateResult;

                if (!client.GetInfo(target, out svnInfoEventArgs))
                {
                    throw new Exception("SVN info failed");
                }

                Uri svnUrl = svnInfoEventArgs.Uri;

                a.ErrorStream = errstream;

                try
                {
                    client.Diff(target, new SvnRevisionRange(Rev1, Rev2), a, outstream);
                }

                catch (Exception)
                {
                    throw new Exception("SVN diff failed");
                    //  return ;
                }


                return;
            }



            //string err = Encoding.Default.GetString(errstream.ToArray());
            //Assert.That(err, Is.EqualTo(string.Empty), "Error in diff: " + err);

            //string apiDiff = Encoding.Default.GetString(outstream.ToArray());
            //string[] clientLines = clientDiff.Split('\n');
            //string[] apiLines = apiDiff.Split('\n');
            //Array.Sort<string>(clientLines);
            //Array.Sort<string>(apiLines);

            //Assert.That(apiLines, Is.EqualTo(clientLines), "Diffs differ");
        }
Example #11
0
        public override void OnExecute(CommandEventArgs e)
        {
            List <string>  toAdd = new List <string>();
            List <SvnItem> items = new List <SvnItem>();

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

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

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

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

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

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

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

            SvnRevisionRange revRange = new SvnRevisionRange(start, end);

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

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

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

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

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

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

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

                    stream.Flush();
                });

                stream.Position = 0;
                using (StreamReader sr = new StreamReader(stream))
                {
                    File.WriteAllText(tempFile, sr.ReadToEnd(), Encoding.UTF8);
                    VsShellUtilities.OpenDocument(e.Context, tempFile);
                }
            }
        }
Example #12
0
        public bool CreatePatch(IEnumerable <PendingChange> changes, PendingChangeCreatePatchArgs args)
        {
            using (PendingCommitState state = new PendingCommitState(Context, changes))
            {
                if (!PreCommit_VerifySingleRoot(state)) // Verify single root 'first'
                {
                    return(false);
                }

                if (!PreCommit_SaveDirty(state))
                {
                    return(false);
                }

                if (args.AddUnversionedFiles)
                {
                    if (!PreCommit_AddNewFiles(state))
                    {
                        return(false);
                    }

                    if (!PreCommit_HandleMissingFiles(state))
                    {
                        return(false);
                    }
                }
                state.FlushState();

                if (!PreCommit_AddNeededParents(state))
                {
                    return(false);
                }

                if (!PreCommit_VerifySingleRoot(state)) // Verify single root 'again'
                {
                    return(false);
                }
            }

            string           relativeToPath  = args.RelativeToPath;
            string           relativeToPathP = relativeToPath.EndsWith("\\") ? relativeToPath : (relativeToPath + "\\");
            string           fileName        = args.FileName;
            SvnRevisionRange revRange        = new SvnRevisionRange(SvnRevision.Base, SvnRevision.Working);

            SvnDiffArgs a = new SvnDiffArgs();

            a.IgnoreAncestry = true;
            a.NoDeleted      = false;
            a.Depth          = SvnDepth.Empty;

            using (MemoryStream stream = new MemoryStream())
            {
                GetService <IProgressRunner>().RunModal(PccStrings.DiffTitle,
                                                        delegate(object sender, ProgressWorkerArgs e)
                {
                    foreach (PendingChange pc in changes)
                    {
                        SvnItem item = pc.SvnItem;
                        SvnWorkingCopy wc;
                        if (!string.IsNullOrEmpty(relativeToPath) &&
                            item.FullPath.StartsWith(relativeToPathP, StringComparison.OrdinalIgnoreCase))
                        {
                            a.RelativeToPath = relativeToPath;
                        }
                        else if ((wc = item.WorkingCopy) != null)
                        {
                            a.RelativeToPath = wc.FullPath;
                        }
                        else
                        {
                            a.RelativeToPath = null;
                        }

                        e.Client.Diff(item.FullPath, revRange, a, stream);
                    }

                    stream.Flush();
                    stream.Position = 0;
                });
                using (StreamReader sr = new StreamReader(stream))
                {
                    string line;

                    // Parse to lines to resolve EOL issues
                    using (StreamWriter sw = File.CreateText(fileName))
                    {
                        while (null != (line = sr.ReadLine()))
                        {
                            sw.WriteLine(line);
                        }
                    }
                }
            }
            return(true);
        }
Example #13
0
        public void Diff_RunDiffTests()
        {
            SvnSandBox sbox = new SvnSandBox(this);

            sbox.Create(SandBoxRepository.Empty, false);
            string WcPath = sbox.Wc;

            string start    = Guid.NewGuid().ToString() + Environment.NewLine + Guid.NewGuid().ToString();
            string end      = Guid.NewGuid().ToString() + Environment.NewLine + Guid.NewGuid().ToString();
            string origLine = Guid.NewGuid().ToString();
            string newLine  = Guid.NewGuid().ToString();

            using (SvnClient client = NewSvnClient(true, false))
            {
                string diffFile = Path.Combine(WcPath, "DiffTest");

                using (StreamWriter sw = File.CreateText(diffFile))
                {
                    sw.WriteLine(start);
                    sw.WriteLine(origLine);
                    sw.WriteLine(end);
                }

                client.Add(diffFile);
                SvnCommitResult ci;
                client.Commit(diffFile, out ci);

                using (StreamWriter sw = File.CreateText(diffFile))
                {
                    sw.WriteLine(start);
                    sw.WriteLine(newLine);
                    sw.WriteLine(end);
                }

                MemoryStream diffOutput = new MemoryStream();

                client.Diff(new SvnPathTarget(diffFile, SvnRevisionType.Head), diffFile, diffOutput);
                VerifyDiffOutput(origLine, newLine, diffOutput);

                diffOutput = new MemoryStream();

                client.Diff(new SvnPathTarget(diffFile, SvnRevisionType.Committed), diffFile, diffOutput);
                VerifyDiffOutput(origLine, newLine, diffOutput);

                diffOutput = new MemoryStream();

                client.Diff(new Uri(sbox.RepositoryUri, "DiffTest"), diffFile, diffOutput);
                VerifyDiffOutput(origLine, newLine, diffOutput);

                SvnCommitResult info;
                client.Commit(diffFile, out info);

                bool visited = false;
                client.DiffSummary(new SvnUriTarget(sbox.RepositoryUri, info.Revision - 1), sbox.RepositoryUri,
                                   delegate(object sender, SvnDiffSummaryEventArgs e)
                {
                    if (e.Path == "DiffTest")
                    {
                        Assert.That(e.DiffKind, Is.EqualTo(SvnDiffKind.Modified));
                        Assert.That(e.PropertiesChanged, Is.False);
                        visited = true;
                    }
                });

                Assert.That(visited);

                int n = 0;

                client.Blame(new SvnPathTarget(diffFile), delegate(object sender, SvnBlameEventArgs e)
                {
                    Assert.That(e.Author, Is.EqualTo(Environment.UserName));
                    Assert.That(e.LineNumber, Is.EqualTo((long)n));
                    switch (n)
                    {
                    case 0:
                    case 1:
                    case 3:
                    case 4:
                        Assert.That(e.Revision, Is.EqualTo(ci.Revision));
                        break;

                    case 2:
                        Assert.That(e.Revision, Is.EqualTo(info.Revision));
                        break;

                    default:
                        Assert.That(false, "EOF");
                        break;
                    }
                    Assert.That(e.Line, Is.Not.Null);
                    n++;
                });

                Assert.That(n, Is.EqualTo(5), "Blame receiver received 5 lines");

                string tempFile = GetTempFile();
                using (FileStream fs = File.Create(tempFile))
                {
                    SvnDiffArgs da = new SvnDiffArgs();
                    da.RelativeToPath = Path.GetDirectoryName(diffFile);
                    client.Diff(diffFile, new SvnRevisionRange(ci.Revision, SvnRevisionType.Head), da, fs);
                }

                client.Update(diffFile, new SvnUpdateArgs {
                    Revision = ci.Revision
                });
                SvnPatchArgs pa = new SvnPatchArgs();
                n          = 0;
                pa.Filter += delegate(object sender, SvnPatchFilterEventArgs e)
                {
                    Assert.That(File.Exists(e.RejectPath));
                    Assert.That(File.Exists(e.ResultPath));
                    Assert.That(new FileInfo(e.RejectPath).Length, Is.EqualTo(0));
                    n++;
                };
                client.Patch(tempFile, Path.GetDirectoryName(diffFile), pa);
                Assert.That(n, Is.EqualTo(1));
            }
        }
Example #14
0
        public void Diff_ReposDiff()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            Uri ReposUrl = sbox.CreateRepository(SandBoxRepository.AnkhSvnCases);
            string clientDiff = this.RunCommand("svn", "diff -r 1:5 " + ReposUrl);

            MemoryStream outstream = new MemoryStream();
            MemoryStream errstream = new MemoryStream();

            SvnDiffArgs a = new SvnDiffArgs();
            a.ErrorStream = errstream;
            Client.Diff(ReposUrl, new SvnRevisionRange(1, 5), a, outstream);

            string err = Encoding.Default.GetString(errstream.ToArray());
            Assert.That(err, Is.EqualTo(string.Empty), "Error in diff: " + err);

            string apiDiff = Encoding.Default.GetString(outstream.ToArray());
            string[] clientLines = clientDiff.Split('\n');
            string[] apiLines = apiDiff.Split('\n');
            Array.Sort<string>(clientLines);
            Array.Sort<string>(apiLines);

            Assert.That(apiLines, Is.EqualTo(clientLines), "Diffs differ");
        }
Example #15
0
        public void Diff_LocalDiff()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            sbox.Create(SandBoxRepository.AnkhSvnCases);
            string WcPath = sbox.Wc;

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

            using (StreamWriter w = new StreamWriter(form, false))
                w.Write("Moo moo moo moo moo\r\nmon\r\nmooo moo moo \r\nssdgo");

            //Necessary to fix up headers

            string clientDiff = this.RunCommand("svn", "diff \"" + form + "\"");

            MemoryStream outstream = new MemoryStream();
            MemoryStream errstream = new MemoryStream();

            SvnDiffArgs a = new SvnDiffArgs();
            a.ErrorStream = errstream;
            this.Client.Diff(
                new SvnPathTarget(form, SvnRevision.Base),
                new SvnPathTarget(form, SvnRevision.Working),
                a, outstream);

            string err = Encoding.Default.GetString(errstream.ToArray());
            Assert.That(err, Is.EqualTo(""), "Error in diff: " + err);
            string apiDiff = Encoding.Default.GetString(outstream.ToArray());
            Assert.That(apiDiff, Is.EqualTo(clientDiff), "Client diff differs");
        }
Example #16
0
        public bool CreatePatch(IEnumerable<PendingChange> changes, PendingChangeCreatePatchArgs args)
        {
            using (PendingCommitState state = new PendingCommitState(Context, changes))
            {
                if (!PreCommit_VerifySingleRoot(state)) // Verify single root 'first'
                    return false;

                if (!PreCommit_SaveDirty(state))
                    return false;

                if (args.AddUnversionedFiles)
                {
                    if (!PreCommit_AddNewFiles(state))
                        return false;

                    if (!PreCommit_HandleMissingFiles(state))
                        return false;
                }
                state.FlushState();

                if (!PreCommit_AddNeededParents(state))
                    return false;

                if (!PreCommit_VerifySingleRoot(state)) // Verify single root 'again'
                    return false;
            }

            string relativeToPath = args.RelativeToPath;
            string relativeToPathP = relativeToPath.EndsWith("\\") ? relativeToPath : (relativeToPath + "\\");
            string fileName = args.FileName;
            SvnRevisionRange revRange = new SvnRevisionRange(SvnRevision.Base, SvnRevision.Working);

            SvnDiffArgs a = new SvnDiffArgs();
            a.IgnoreAncestry = true;
            a.NoDeleted = false;
            a.Depth = SvnDepth.Empty;

            using (MemoryStream stream = new MemoryStream())
            {
                GetService<IProgressRunner>().RunModal(PccStrings.DiffTitle,
                    delegate(object sender, ProgressWorkerArgs e)
                    {
                        foreach (PendingChange pc in changes)
                        {
                            SvnItem item = pc.SvnItem;
                            SvnWorkingCopy wc;
                            if (!string.IsNullOrEmpty(relativeToPath)
                                && item.FullPath.StartsWith(relativeToPathP, StringComparison.OrdinalIgnoreCase))
                                a.RelativeToPath = relativeToPath;
                            else if ((wc = item.WorkingCopy) != null)
                                a.RelativeToPath = wc.FullPath;
                            else
                                a.RelativeToPath = null;

                            e.Client.Diff(item.FullPath, revRange, a, stream);
                        }

                        stream.Flush();
                        stream.Position = 0;
                    });
                using (StreamReader sr = new StreamReader(stream))
                {
                    string line;

                    // Parse to lines to resolve EOL issues
                    using (StreamWriter sw = File.CreateText(fileName))
                    {
                        while (null != (line = sr.ReadLine()))
                            sw.WriteLine(line);
                    }
                }
            }
            return true;
        }
Example #17
0
        public void Diff_RunDiffTests()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            sbox.Create(SandBoxRepository.Empty, false);
            string WcPath = sbox.Wc;

            string start = Guid.NewGuid().ToString() + Environment.NewLine + Guid.NewGuid().ToString();
            string end = Guid.NewGuid().ToString() + Environment.NewLine + Guid.NewGuid().ToString();
            string origLine = Guid.NewGuid().ToString();
            string newLine = Guid.NewGuid().ToString();
            using (SvnClient client = NewSvnClient(true, false))
            {
                string diffFile = Path.Combine(WcPath, "DiffTest");

                using (StreamWriter sw = File.CreateText(diffFile))
                {
                    sw.WriteLine(start);
                    sw.WriteLine(origLine);
                    sw.WriteLine(end);
                }

                client.Add(diffFile);
                SvnCommitResult ci;
                client.Commit(diffFile, out ci);

                using (StreamWriter sw = File.CreateText(diffFile))
                {
                    sw.WriteLine(start);
                    sw.WriteLine(newLine);
                    sw.WriteLine(end);
                }

                MemoryStream diffOutput = new MemoryStream();

                client.Diff(new SvnPathTarget(diffFile, SvnRevisionType.Head), diffFile, diffOutput);
                VerifyDiffOutput(origLine, newLine, diffOutput);

                diffOutput = new MemoryStream();

                client.Diff(new SvnPathTarget(diffFile, SvnRevisionType.Committed), diffFile, diffOutput);
                VerifyDiffOutput(origLine, newLine, diffOutput);

                diffOutput = new MemoryStream();

                client.Diff(new Uri(sbox.RepositoryUri, "DiffTest"), diffFile, diffOutput);
                VerifyDiffOutput(origLine, newLine, diffOutput);

                SvnCommitResult info;
                client.Commit(diffFile, out info);

                bool visited = false;
                client.DiffSummary(new SvnUriTarget(sbox.RepositoryUri, info.Revision - 1), sbox.RepositoryUri,
                    delegate(object sender, SvnDiffSummaryEventArgs e)
                    {
                        if (e.Path == "DiffTest")
                        {
                            Assert.That(e.DiffKind, Is.EqualTo(SvnDiffKind.Modified));
                            Assert.That(e.PropertiesChanged, Is.False);
                            visited = true;
                        }
                    });

                Assert.That(visited);

                int n = 0;

                client.Blame(new SvnPathTarget(diffFile), delegate(object sender, SvnBlameEventArgs e)
                {
                    Assert.That(e.Author, Is.EqualTo(Environment.UserName));
                    Assert.That(e.LineNumber, Is.EqualTo((long)n));
                    switch (n)
                    {
                        case 0:
                        case 1:
                        case 3:
                        case 4:
                            Assert.That(e.Revision, Is.EqualTo(ci.Revision));
                            break;
                        case 2:
                            Assert.That(e.Revision, Is.EqualTo(info.Revision));
                            break;
                        default:
                            Assert.That(false, "EOF");
                            break;
                    }
                    Assert.That(e.Line, Is.Not.Null);
                    n++;
                });

                Assert.That(n, Is.EqualTo(5), "Blame receiver received 5 lines");

                string tempFile = GetTempFile();
                using (FileStream fs = File.Create(tempFile))
                {
                    SvnDiffArgs da = new SvnDiffArgs();
                    da.RelativeToPath = Path.GetDirectoryName(diffFile);
                    client.Diff(diffFile, new SvnRevisionRange(ci.Revision, SvnRevisionType.Head), da, fs);
                }

                client.Update(diffFile, new SvnUpdateArgs { Revision = ci.Revision });
                SvnPatchArgs pa = new SvnPatchArgs();
                n = 0;
                pa.Filter += delegate(object sender, SvnPatchFilterEventArgs e)
                {
                    Assert.That(File.Exists(e.RejectPath));
                    Assert.That(File.Exists(e.ResultPath));
                    Assert.That(new FileInfo(e.RejectPath).Length, Is.EqualTo(0));
                    n++;
                };
                client.Patch(tempFile, Path.GetDirectoryName(diffFile), pa);
                Assert.That(n, Is.EqualTo(1));
            }
        }