public void MultipleHeadsOkIfSpecified()
        {
            using (var pullFromDirectory = new SelfCleaningDirectory())
            {
                var pullFromPath = pullFromDirectory.Path;
                var provider = GetProvider(pullFromPath);
                provider.Init();

                WriteAndCommitRandomFile(pullFromDirectory);

                var firstRev = provider.CurrentRevision;

                WriteAndCommitRandomFile(pullFromDirectory);

                provider.Update(firstRev);

                WriteAndCommitRandomFile(pullFromDirectory);

                using (var workingDirectory = new SelfCleaningDirectory())
                {
                    var workingPath = workingDirectory.Path;
                    var sourceControl = new HgSourceControl(new HgXmlLogParser(),
                                                            new TestProcessExecutor())
                                        {
                                            SourceRepository = pullFromPath,
                                            FailIfMultipleHeads = false,
                                        };
                    var fromResult = new MockIntegrationResult { WorkingDirectory = workingPath };
                    var toResult = new MockIntegrationResult { WorkingDirectory = workingPath };
                    var modifications = sourceControl.GetModifications(fromResult, toResult);
                    Assert.That(modifications.Length, Is.EqualTo(3));
                }
            }
        }
 public void CheckVersion()
 {
     using (var repoDirectory = new SelfCleaningDirectory())
     {
         var provider = CreateProvider(repoDirectory);
         var version = provider.Version;
         Assert.That(version, Is.GreaterThan(new Version(0, 0)));
     }
 }
Ejemplo n.º 3
0
 public void DetectsRepositoryTheCheapWay()
 {
     using (var repoDirectory = new SelfCleaningDirectory())
     {
         var hg = new Hg(new HgProcess(), new HgXmlLogParser(), repoDirectory.Path);
         Assert.That(hg.IsRepository, Is.False);
         Directory.CreateDirectory(Path.Combine(repoDirectory.Path, ".hg"));
         Assert.That(hg.IsRepository);
     }
 }
 public void GetLog()
 {
     using (var repoDirectory = new SelfCleaningDirectory())
     {
         var provider = CreateProvider(repoDirectory);
         InitializeRepository(repoDirectory);
         Enumerable.Range(1, 5).ToList().ForEach(i => AddRandomCommit(repoDirectory));
         var actual = provider.Log(Branch.Default, Revision.First.Through(Branch.Default.AsTag().AsRevision()));
         Assert.That(actual.Count, Is.EqualTo(5));
     }
 }
 public void GetLogWithSameRevision()
 {
     using (var repoDirectory = new SelfCleaningDirectory())
     {
         InitializeRepository(repoDirectory);
         AddRandomCommit(repoDirectory);
         AddRandomCommit(repoDirectory);
         var provider = CreateProvider(repoDirectory);
         var actual = provider.Log(Branch.Default, Revision.First.Through(Revision.First));
         Assert.That(actual.Count, Is.EqualTo(1));
     }
 }
 public void GetsCorrectRevisionForTag()
 {
     using (var repoDirectory = new SelfCleaningDirectory())
     {
         var provider = CreateProvider(repoDirectory);
         InitializeRepository(repoDirectory);
         AddRandomCommit(repoDirectory);
         var expected = provider.CurrentRevision;
         var tag = new Tag("Whoop whoop");
         TagCurrent(repoDirectory, tag);
         AddRandomCommit(repoDirectory);
         Assert.That(provider.GetRevisionForTag(tag), Is.EqualTo(expected));
     }
 }
Ejemplo n.º 7
0
 public void VersionNaughtDotNaughtReturnedWhenVersionTextNotFound()
 {
     var processMock = new Mock<IHgProcess>();
     processMock
         .Setup(p => p.Execute(It.IsAny<HgArguments>()))
         .Returns(new HgResult(false, "I have no idea what you're talking about.", ""))
         .AtMostOnce()
         .Verifiable();
     using (var repoDirectory = new SelfCleaningDirectory())
     {
         var hg = new Hg(processMock.Object, new HgXmlLogParser(), repoDirectory.Path);
         var actual = hg.Version;
         Assert.That(actual, Is.EqualTo(new Version(0, 0)));
     }
 }
 public void CurrentBranchFunctionsAsDesigned()
 {
     var expected = new Branch("differenty");
     using (var repoDirectory = new SelfCleaningDirectory())
     {
         InitializeRepository(repoDirectory);
         Enumerable.Range(1, 5).ToList().ForEach(i => AddRandomCommit(repoDirectory));
         ChangeToBranch(repoDirectory, expected);
         Enumerable.Range(1, 5).ToList().ForEach(i => AddRandomCommit(repoDirectory));
         var provider = new Hg(DefaultProcessExecutor, _defaultXmlLogParser, repoDirectory.Path);
         provider.Update(Branch.Default.AsTag().AsRevision());
         Assert.That(provider.CurrentBranch, Is.EqualTo(Branch.Default));
         provider.Update(expected.AsTag().AsRevision());
         Assert.That(provider.CurrentBranch, Is.EqualTo(expected));
     }
 }
Ejemplo n.º 9
0
 public void VersionFindsAnyVersionyLookingThingInFirstLine()
 {
     var processMock = new Mock<IHgProcess>();
     processMock
         .Setup(p => p.Execute(It.IsAny<HgArguments>()))
         .Returns(new HgResult(false,
                               "I have no idea what you're talking about, but version 51.50.\r\nMaybe you mean version 19.84?",
                               ""))
         .AtMostOnce()
         .Verifiable();
     using (var repoDirectory = new SelfCleaningDirectory())
     {
         var hg = new Hg(processMock.Object, new HgXmlLogParser(), repoDirectory.Path);
         var actual = hg.Version;
         Assert.That(actual, Is.EqualTo(new Version(51, 50)));
     }
 }
        public void MultipleHeadsFail()
        {
            using (var pullFromDirectory = new SelfCleaningDirectory())
            {
                var pullFromPath = pullFromDirectory.Path;
                var provider = GetProvider(pullFromPath);
                provider.Init();

                WriteAndCommitRandomFile(pullFromDirectory);

                var firstRev = provider.CurrentRevision;

                WriteAndCommitRandomFile(pullFromDirectory);

                provider.Update(firstRev);

                WriteAndCommitRandomFile(pullFromDirectory);

                using (var workingDirectory = new SelfCleaningDirectory())
                {
                    var workingPath = workingDirectory.Path;
                    var sourceControl = new HgSourceControl(new HgXmlLogParser(),
                                                            new TestProcessExecutor())
                                        {
                                            SourceRepository = pullFromPath,
                                            FailIfMultipleHeads = true,
                                        };
                    var fromResult = new MockIntegrationResult { WorkingDirectory = workingPath };
                    var toResult = new MockIntegrationResult { WorkingDirectory = workingPath };
                    Assert.That(
                                () => { sourceControl.GetModifications(fromResult, toResult); },
                                Throws.TypeOf(typeof(HgSourceControlException)).With.Property("Message").EqualTo(
                                                                                                                 "Multiple or no heads in branch 'default'."));
                }
            }
        }
 private static string WriteAndCommitRandomFile(SelfCleaningDirectory repoDirectory)
 {
     var fileContent = Encoding.ASCII.GetString((new byte[8196]).Tap(b => new Random().NextBytes(b)));
     var filePath = Path.Combine(repoDirectory.Path, Path.GetRandomFileName());
     using (var stream = File.CreateText(filePath))
     {
         stream.Write(fileContent);
     }
     var provider = GetProvider(repoDirectory.Path);
     provider.AddRemove();
     provider.Commit(DateTimeOffset.Now.ToString(CultureInfo.InvariantCulture));
     return Path.GetFileName(filePath);
 }
        public void Simple()
        {
            using (var pullFromDirectory = new SelfCleaningDirectory())
            {
                var pullFromPath = pullFromDirectory.Path;
                var provider = GetProvider(pullFromPath);
                provider.Init();

                var fileName = WriteAndCommitRandomFile(pullFromDirectory);

                using (var workingDirectory = new SelfCleaningDirectory())
                {
                    var workingPath = workingDirectory.Path;
                    var sourceControl = new HgSourceControl(new HgXmlLogParser(),
                                                            new TestProcessExecutor())
                                        {
                                            SourceRepository = pullFromPath,
                                        };
                    var fromResult = new MockIntegrationResult { WorkingDirectory = workingPath };
                    var toResult = new MockIntegrationResult { WorkingDirectory = workingPath };
                    var modifications = sourceControl.GetModifications(fromResult, toResult);
                    Assert.That(modifications.Length, Is.EqualTo(1));
                    var modification = modifications.Single();
                    Assert.That(modification.ModifiedTime, Is.GreaterThan(DateTime.Now.AddMinutes(-1)));
                    Assert.That(modification.FileName, Is.EqualTo(fileName));

                    sourceControl.GetSource(toResult);

                    var workingProvider = GetProvider(workingPath);
                    Assert.That(modification.Version, Is.StringStarting(workingProvider.CurrentRevision.ToString()));
                }
            }
        }
 public void IgnoresFlagsOnRevisions()
 {
     using (var repoDirectory = new SelfCleaningDirectory())
     {
         InitializeRepository(repoDirectory);
         var randomFile = WriteRandomFile(repoDirectory);
         AddRemoveFiles(repoDirectory);
         var provider = CreateProvider(repoDirectory);
         Assert.That(provider.CurrentRevision, Is.EqualTo(Revision.BeforeFirst));
         CommitChanges(repoDirectory);
         var expectedRevision = provider.CurrentRevision;
         MangleFile(randomFile);
         Assert.That(provider.CurrentRevision, Is.EqualTo(expectedRevision));
     }
 }
 private static string WriteRandomFile(SelfCleaningDirectory selfCleaningDirectory)
 {
     var path = Path.Combine(selfCleaningDirectory.Path, Path.GetRandomFileName());
     MangleFile(path);
     return path;
 }
 public void LogWithNoRevisionsIsOk()
 {
     using (var repoDirectory = new SelfCleaningDirectory())
     {
         var provider = CreateProvider(repoDirectory);
         InitializeRepository(repoDirectory);
         var actual = provider.Log(Branch.Default, Revision.BeforeFirst.Through(Revision.BeforeFirst));
         Assert.That(actual.Count, Is.EqualTo(0));
     }
 }
 private static void InitializeRepository(SelfCleaningDirectory repoDirectory)
 {
     var hgArguments = HgArguments.Init(repoDirectory.Path);
     AssertResultNotFailed(DefaultProcessExecutor.Execute(hgArguments));
 }
        public void TagSupport()
        {
            using (var pullFromDirectory = new SelfCleaningDirectory())
            {
                const string tagName = "Test tag";

                var pullFromPath = pullFromDirectory.Path;
                var provider = GetProvider(pullFromPath);
                provider.Init();

                WriteAndCommitRandomFile(pullFromDirectory);

                var taggedRevision = provider.CurrentRevision;
                provider.Tag(taggedRevision, tagName, false);

                using (var workingDirectory = new SelfCleaningDirectory())
                {
                    var workingPath = workingDirectory.Path;
                    var sourceControl = new HgSourceControl(new HgXmlLogParser(),
                                                            new TestProcessExecutor())
                                        {
                                            SourceRepository = pullFromPath,
                                            TagRaw = tagName,
                                        };
                    var fromResult = new MockIntegrationResult { WorkingDirectory = workingPath };
                    var toResult = new MockIntegrationResult { WorkingDirectory = workingPath };
                    var modifications = sourceControl.GetModifications(fromResult, toResult);
                    Assert.That(modifications.Length, Is.EqualTo(1));
                    Assert.That(modifications.Single().Version, Is.StringStarting(taggedRevision.ToString()));

                    sourceControl.GetSource(toResult);

                    WriteAndCommitRandomFile(pullFromDirectory);

                    var moreModifications = sourceControl.GetModifications(toResult,
                                                                           new MockIntegrationResult { WorkingDirectory = workingPath });
                    Assert.That(moreModifications.Length, Is.EqualTo(0));

                    provider.Tag(provider.CurrentRevision, tagName, true);

                    var evenMoreModifications = sourceControl.GetModifications(toResult,
                                                                               new MockIntegrationResult
                                                                               { WorkingDirectory = workingPath });
                    Assert.That(evenMoreModifications.Length, Is.EqualTo(2));
                }
            }
        }
 private static void ChangeToBranch(SelfCleaningDirectory repoDirectory, Branch branch)
 {
     var hgArguments = HgArguments.ChangeBranch(branch).AddRepository(repoDirectory.Path);
     AssertResultNotFailed(DefaultProcessExecutor.Execute(hgArguments));
 }
 private static void AddRemoveFiles(SelfCleaningDirectory selfCleaningDirectory)
 {
     var hgArguments = HgArguments
         .AddRemove()
         .Similarity(50)
         .AddRepository(selfCleaningDirectory.Path);
     AssertResultNotFailed(DefaultProcessExecutor.Execute(hgArguments));
 }
 private static void AddRandomCommit(SelfCleaningDirectory selfCleaningDirectory)
 {
     WriteRandomFile(selfCleaningDirectory);
     AddRemoveFiles(selfCleaningDirectory);
     CommitChanges(selfCleaningDirectory);
 }
 public void GetsCorrectRevisionWhenNoRevisions()
 {
     using (var repoDirectory = new SelfCleaningDirectory())
     {
         var provider = CreateProvider(repoDirectory);
         InitializeRepository(repoDirectory);
         Assert.That(provider.CurrentRevision, Is.EqualTo(Revision.BeforeFirst));
     }
 }
 private static void TagCurrent(SelfCleaningDirectory repoDirectory, Tag tag)
 {
     var hgArguments = HgArguments
         .Tag(tag.ToString())
         .AddRepository(repoDirectory.Path);
     AssertResultNotFailed(DefaultProcessExecutor.Execute(hgArguments));
 }
 private static void CommitChanges(SelfCleaningDirectory selfCleaningDirectory)
 {
     var hgArguments = HgArguments
         .Commit(DateTimeOffset.Now.Ticks.ToString())
         .AddRepository(selfCleaningDirectory.Path);
     AssertResultNotFailed(DefaultProcessExecutor.Execute(hgArguments));
 }
 public void IsRepository()
 {
     using (var repoDirectory = new SelfCleaningDirectory())
     {
         var provider = CreateProvider(repoDirectory);
         Assert.That(provider.IsRepository, Is.False);
         InitializeRepository(repoDirectory);
         Assert.That(provider.IsRepository);
     }
 }
 private static Hg CreateProvider(SelfCleaningDirectory repoDirectory)
 {
     return new Hg(DefaultProcessExecutor, _defaultXmlLogParser, repoDirectory.Path);
 }
        public void SimulateMoreModifications()
        {
            using (var pullFromDirectory = new SelfCleaningDirectory())
            {
                var pullFromPath = pullFromDirectory.Path;
                var provider = GetProvider(pullFromPath);
                provider.Init();

                var firstFile = WriteAndCommitRandomFile(pullFromDirectory);
                var firstRevision = provider.CurrentRevision;

                using (var workingDirectory = new SelfCleaningDirectory())
                {
                    var workingPath = workingDirectory.Path;
                    var sourceControl = new HgSourceControl(new HgXmlLogParser(),
                                                            new TestProcessExecutor())
                                        {
                                            SourceRepository = pullFromPath,
                                        };
                    var fromResult = new MockIntegrationResult { WorkingDirectory = workingPath };
                    var toResult = new MockIntegrationResult { WorkingDirectory = workingPath };
                    var modifications = sourceControl.GetModifications(fromResult, toResult);
                    Assert.That(modifications.Length, Is.EqualTo(1));
                    Assert.That(modifications.Single().FileName, Is.EqualTo(firstFile));
                    Assert.That(modifications.Single().Version, Is.StringStarting(firstRevision.ToString()));

                    sourceControl.GetSource(toResult);

                    var secondFile = WriteAndCommitRandomFile(pullFromDirectory);
                    var secondRevision = provider.CurrentRevision;

                    var againToResult = new MockIntegrationResult { WorkingDirectory = workingPath };
                    var moreModifications = sourceControl.GetModifications(toResult, againToResult);
                    Assert.That(moreModifications.Length, Is.EqualTo(1));
                    Assert.That(moreModifications.Single().FileName, Is.EqualTo(secondFile));
                    Assert.That(moreModifications.Single().Version, Is.StringStarting(secondRevision.ToString()));
                }
            }
        }