public void ImplicitConversion_RevisionsToString_ExtractsTheSpecification() { RevSpec revSpec = RevSpec.Range(17, 42); string value = revSpec; Assert.That(value, Is.EqualTo("17:42")); }
public Changeset GetCommit(RevisionId id) { var command = new LogCommand().WithRevision(RevSpec.ById(id.Value)).WithIncludePathActions(); var changeset = _repository.Log(command).FirstOrDefault(ch => ch.Hash == id.Value); return(changeset); }
public void To_WithRevisionByRevisionNumber_ProducesCorrectRevisionSpecification() { string output = RevSpec.To(7).ToString(); const string expected = ":7"; Assert.That(output, Is.EqualTo(expected)); }
/// <summary> /// Gets a <see cref="HgLogQuery"/> that selects commits witch are not only tagging commits. /// </summary> public HgLogQuery ExceptTaggingCommits() { return(Revision.Except( RevSpec.Affects(".hgtags") & RevSpec.Grep("Added tag .+ for changeset .+") & !RevSpec.Tagged())); }
private ChangeSet GetChangeSet(RevSpec id) { var log = Enumerable.Empty <Changeset>(); try { log = Repository.Log(id); } catch (MercurialExecutionException e) { // Older Mercurial (e.g. 2.4.1) were returning empty without errors when called with an unknown revision, // but newer versions (e.g. 2.7.1) actually fail here, so account for that possibility so we can run on both if (!e.Message.Contains("unknown revision")) { throw; } } var changeset = log.SingleOrDefault(); if (changeset != null) { return(CreateChangeSet(changeset)); } return(null); }
public void Pull_FromOtherWithRevisionSpecification_OnlyPullsInRelevantChanges() { WriteTextFileAndCommit(Repo1, "test1.txt", "initial contents", "initial commit", true); WriteTextFileAndCommit(Repo1, "test1.txt", "changed contents", "2nd commit", false); WriteTextFileAndCommit(Repo1, "test1.txt", "changed contents again", "3rd commit", false); Repo2.Pull( Repo1.Path, new PullCommand { Revisions = { RevSpec.Single(1), }, }); Changeset[] pulledChangesets = Repo2.Log().OrderBy(c => c.RevisionNumber).ToArray(); Changeset[] originalChangesets = Repo1.Log( new LogCommand { Revisions = { RevSpec.Range(0, 1), }, }).OrderBy(c => c.RevisionNumber).ToArray(); CollectionAssert.AreEqual(pulledChangesets, originalChangesets); }
static void Main(string[] args) { Mercurial.Repository repo = new Repository(@"C:\Users\vddungenpeter\source\repos\Test"); RevSpec working = repo.Identify(); //foreach (var changeSet in repo.Log()) //{ // Console.WriteLine(changeSet); // if (changeSet.Revision == working) // { // Console.WriteLine("*** Working changeset!"); // } //} //Mercurial.Gui.GuiClient.ClientType = GuiClientType.PyQT; var cmd = new WriteGuiConsole(); Mercurial.Client.SetClientPath(@"C:\Program Files\TortoiseHG"); if (Client.CouldLocateClient) { repo.Execute(cmd); //Client.Execute(new RevertCommand()); } //Mercurial.Gui.GuiClient.InitGui(repo); Console.ReadLine(); }
/// <inheritdoc /> public ICommit GetBranchHead(string branchName) { var heads = _repository.Heads(new HeadsCommand() .WithBranchRevision(RevSpec.ByBranch(branchName))); return((HgCommit)heads.First()); }
public void ByBranch_ForVariousTestCases_ProducesCorrectRevisionSpecification(string input, string expected) { RevSpec rev = RevSpec.ByBranch(input); string output = rev.ToString(); Assert.That(output, Is.EqualTo(expected)); }
public void ByTag_WithNameSurroundedBySpaces_ReturnsTrimmedName() { string output = RevSpec.ByTag(" stable ").ToString(); const string expected = "stable"; Assert.That(output, Is.EqualTo(expected)); }
public void ImplicitConversion_StringToRevisions_ProducesCorrectRevisionsValue() { const string hash = "72beff810"; RevSpec revSpec = hash; Assert.That(revSpec.ToString(), Is.EqualTo(hash)); }
public void ByHash_CorrectHashSurroundedByWhitespace_ReturnsTrimmedHash() { string output = RevSpec.Single(" 123abc ").ToString(); const string expected = "123abc"; Assert.That(output, Is.EqualTo(expected)); }
public void ByHash_UppercaseHash_ReturnsLowercaseHash() { string output = RevSpec.Single("123ABC").ToString(); const string expected = "123abc"; Assert.That(output, Is.EqualTo(expected)); }
public void Update(RevSpec rev) { using (Logger.IndentLog($"Update working directory to a revision: {rev}")) { _repository.Update(rev); } }
public void Range_WithTwoRevisionsByRevisionNumber_ProducesCorrectRevisionSpecification() { string output = RevSpec.Range(2, 7).ToString(); const string expected = "2:7"; Assert.That(output, Is.EqualTo(expected)); }
public ICommit GetCommit(RevSpec revision) { using (Logger.IndentLog($"Get commit by rev: {revision}")) { return(_repository.GetCommit(revision)); } }
public void Not_OnSimpleRange_CreatesCorrectExpression() { string output = (!RevSpec.Range(2, 7)).ToString(); const string expected = "not 2:7"; Assert.That(output, Is.EqualTo(expected)); }
/// <inheritdoc /> public ICommit GetCommit(RevSpec revision) { var query = new HgLogQuery(revision) .Last(); return((HgCommit)Log(query).First()); }
public void Log_WithMultipleRevisionFilters_OnlyIncludeMatchingChangesets() { Repo.Init(); foreach (string filename in new[] { "test1.txt", "test2.txt", "test3.txt" }) { File.WriteAllText(Path.Combine(Repo.Path, filename), "dummy content"); Repo.Commit( filename + " added", new CommitCommand { AddRemove = true, }); } Changeset[] log = Repo.Log( new LogCommand { Revisions = { RevSpec.Range(RevSpec.Single(0), RevSpec.Single(0)), RevSpec.Range(RevSpec.Single(2), RevSpec.Single(2)), }, }).ToArray(); Assert.That(log.Length, Is.EqualTo(2)); }
public static MergeResult HgMerge(this ICakeContext context, DirectoryPath repositoryPath, string sourceBranch, string destinationBranch = null) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (repositoryPath == null) { throw new ArgumentNullException(nameof(repositoryPath)); } if (sourceBranch == null) { throw new ArgumentNullException(nameof(sourceBranch)); } using (var repository = context.Hg(repositoryPath)) { if (!string.IsNullOrEmpty(destinationBranch)) { repository.Update(destinationBranch); } else { destinationBranch = repository.Summary().Branch; } MergeResult result; try { result = repository.Merge(RevSpec.ByBranch(sourceBranch), new MergeCommand { MergeTool = ":merge" }); } catch (MercurialExecutionException ex) { if (!ex.Message.Contains("merging with a working directory ancestor has no effect")) { throw; } result = MergeResult.UnresolvedFiles; } if (result == MergeResult.Success) { repository.Commit($"Merge with {sourceBranch}"); } else { repository.Update(new UpdateCommand { Clean = true }); } return(result); } }
public void Except_ProducesCorrectRevisionSpecification() { RevSpec include = RevSpec.Range(2, 7); RevSpec exclude = RevSpec.Single(5); RevSpec result = include.Except(exclude); Assert.That(result.ToString(), Is.EqualTo("2:7 - 5")); }
public void Children_OfRange_ProducesCorrectRevisionSpecification() { RevSpec revSpec = RevSpec.Range(2, 17); string output = revSpec.Children.ToString(); Assert.That(output, Is.EqualTo("children(2:17)")); }
/// <inheritdoc /> public ICommit GetCommit(RevSpec revision) { var log = _repository.Log(new LogCommand() .WithRevision(revision) .WithAdditionalArgument("--limit 1")); return((HgCommit)log.First()); }
public void Author_WithName_ProducesCorrectRevisionSpecification() { RevSpec revSpec = RevSpec.Author("Lasse V. Karlsen <*****@*****.**>"); string output = revSpec.ToString(); Assert.That(output, Is.EqualTo("author('Lasse V. Karlsen <*****@*****.**>')")); }
public void And_WithOtherRevisions_ProducesCorrectRevisionSpecification() { RevSpec rev1 = RevSpec.Range(2, 7); RevSpec rev2 = RevSpec.Range(10, 14); RevSpec result = rev1.And(rev2); Assert.That(result.ToString(), Is.EqualTo("2:7 and 10:14")); }
public void Branches_ForRange_ProducesCorrectRevisionSpecification() { RevSpec revSpec = RevSpec.Range(2, 17); string output = revSpec.Branches.ToString(); Assert.That(output, Is.EqualTo("branch(2:17)")); }
/// <summary> /// Initializes a new instance of the <see cref="BisectResult"/> class. /// </summary> /// <param name="revision"> /// The revision the <see cref="BisectCommand"/> is currently at in the repository. /// </param> /// <param name="done"> /// If <c>true</c>, then <paramref name="revision"/> specifies the first good changeset in the /// repository; otherwise <paramref name="revision"/> specifies the current changeset that should /// be tested and marked good or bad by executing another <see cref="BisectCommand"/>. /// </param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="revision"/> is <c>null</c>.</para> /// </exception> public BisectResult(RevSpec revision, bool done) { if (revision == null) throw new ArgumentNullException("revision"); _Revision = revision; _Done = done; }
public void OperatorOr_ReturnsCorrectExpression() { var r1 = new RevSpec("10"); var r2 = new RevSpec("20"); RevSpec r = r1 || r2; Assert.That(r, Is.EqualTo(new RevSpec("10 or 20"))); }
/// <summary> /// Returns a <see cref="HgLogQuery"/> that selects a commit based on its unique hash number. /// </summary> /// <param name="hash">The commit unique hash.</param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="hash"/> is <c>null</c> or empty.</para> /// </exception> public HgLogQuery Single(string hash) { if (string.IsNullOrEmpty(hash)) { throw new ArgumentNullException(nameof(hash)); } return(RevSpec.Single(hash)); }
/// <summary> /// Creates a <see cref="HgLogQuery"/> that finds commits that belong to the named branch. /// </summary> /// <param name="name">Branch name.</param> public HgLogQuery ByBranch(string name) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } return(RevSpec.ByBranch(name)); }
/// <summary> /// Create a <see cref="HgLogQuery"/> that includes the commit /// specified and all ancestor commits. /// </summary> /// <param name="query">The <see cref="HgLogQuery"/> to end with.</param> public HgLogQuery AncestorsOf(HgLogQuery query) { if (query == null) { throw new ArgumentNullException(nameof(query)); } return(RevSpec.AncestorsOf(query.Revision)); }
public IEnumerable<RevisionRange> GetAfterTillHead(RevisionId revisionId, int pageSize) { var revSpec = new RevSpec(revisionId.Value); var command = new LogCommand().WithRevision(RevSpec.From(revSpec) && !new RevSpec(revisionId.Value)); var pages = _repository.Log(command) .OrderBy(ch => ch.Timestamp) .ToArray() .Split(pageSize); var result = pages.Select(page => new RevisionRange(page.First().ToRevisionId(), page.Last().ToRevisionId())); return result; }
public IEnumerable<RevisionRange> GetFromAndBefore(RevisionId fromRevision, RevisionId toRevision, int pageSize) { var from = new RevSpec(fromRevision.Value); var to = new RevSpec(toRevision.Value); var command = new LogCommand().WithRevision(RevSpec.Range(from, to)); var pages = _repository.Log(command) .OrderBy(ch => ch.Timestamp) .ToArray() .Split(pageSize); var result = pages.Select(page => new RevisionRange(page.First().ToRevisionId(), page.Last().ToRevisionId())); return result; }
public IEnumerable<RevisionRange> GetFromAndBefore(RevisionId fromRevision, RevisionId toRevision, int pageSize) { var command = new LogCommand(); if (string.IsNullOrEmpty(fromRevision.Value)) { if (string.IsNullOrEmpty(toRevision.Value)) { command = command.WithAdditionalArgument("-d {0:yyyy-MM-dd} to {1:yyyy-MM-dd}".Fmt(fromRevision.Time.Value, toRevision.Time.Value)); } else { var to = new RevSpec(toRevision.Value); command = command.WithRevision(RevSpec.To(to)); command = command.WithAdditionalArgument("-d >{0:yyyy-MM-dd}".Fmt(fromRevision.Time.Value)); } } else { var from = new RevSpec(fromRevision.Value); if (string.IsNullOrEmpty(toRevision.Value)) { command = command.WithAdditionalArgument("-d <{0:yyyy-MM-dd}".Fmt(toRevision.Time.Value)); command = command.WithRevision(RevSpec.From(from)); } else { var to = new RevSpec(toRevision.Value); command = command.WithRevision(RevSpec.Range(from, to)); } } var pages = _repository.Log(command) .OrderBy(ch => ch.Timestamp) .ToArray() .Split(pageSize); var result = pages.Select(page => new RevisionRange(page.First().ToRevisionId(), page.Last().ToRevisionId())); return result; }
/// <summary> /// Strip changesets from the repository. /// </summary> /// <param name="repository"> /// The <see cref="Repository"/> to strip changesets from. /// </param> /// <param name="revision"> /// The <see cref="RevSpec"/> of the revision to strip. /// </param> /// <param name="command"> /// Any extra options to the strip method, or <c>null</c> for default options. /// </param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="repository"/> is <c>null</c>.</para> /// <para>- or -</para> /// <para><paramref name="revision"/> is <c>null</c>.</para> /// </exception> public static void StripGui(this Repository repository, RevSpec revision, StripGuiCommand command = null) { if (repository == null) throw new ArgumentNullException("repository"); if (revision == null) throw new ArgumentNullException("revision"); command = (command ?? new StripGuiCommand()) .WithRevision(revision); repository.Execute(command); }
/// <summary> /// Rebase changesets. /// </summary> /// <param name="repository"> /// The <see cref="Repository"/> to rebase changesets in. /// </param> /// <param name="sourceRevision"> /// The source revision to rebase. This changeset, and all its descendants, will be rebased. /// </param> /// <param name="destinationRevision"> /// The Destination revision to rebase. This changeset will be the parent of the changesets after the rebase. /// </param> /// <param name="command"> /// Any extra options to the rebase method, or <c>null</c> for default options. /// </param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="repository"/> is <c>null</c>.</para> /// <para>- or -</para> /// <para><paramref name="sourceRevision"/> is <c>null</c>.</para> /// <para>- or -</para> /// <para><paramref name="destinationRevision"/> is <c>null</c>.</para> /// </exception> /// <exception cref="ArgumentException"> /// <para><see cref="RebaseGuiCommand.SourceRevision"/> cannot be set before calling this method.</para> /// <para>- or -</para> /// <para><see cref="RebaseGuiCommand.DestinationRevision"/> cannot be set before calling this method.</para> /// </exception> /// <remarks> /// This command is only available for the <see cref="GuiClientType.PyQT"/> client type. /// </remarks> public static void RebaseGui(this Repository repository, RevSpec sourceRevision, RevSpec destinationRevision, RebaseGuiCommand command = null) { if (repository == null) throw new ArgumentNullException("repository"); if (sourceRevision == null) throw new ArgumentNullException("sourceRevision"); if (destinationRevision == null) throw new ArgumentNullException("destinationRevision"); if (command != null && command.SourceRevision != null) throw new ArgumentException("RebaseGuiCommand.SourceRevision cannot be set before calling this method", "command"); if (command != null && command.DestinationRevision != null) throw new ArgumentException("RebaseGuiCommand.DestinationRevision cannot be set before calling this method", "command"); command = (command ?? new RebaseGuiCommand()) .WithSourceRevision(sourceRevision) .WithDestinationRevision(destinationRevision); repository.Execute(command); }
public override DiffInfo GenerateDiff(FilePath baseLocalPath, VersionInfo vi) { var rev = new RevSpec (((MercurialRevision) vi.Revision).ShortName); string diff = RootRepository.Diff (new global::Mercurial.DiffCommand ().WithIncludePattern (vi.LocalPath).WithRevisions (rev)); return new DiffInfo (baseLocalPath, vi.LocalPath, diff); /* try { if ((vi.Status & VersionStatus.ScheduledAdd) != 0) { var ctxt = GetFileContent (vi.LocalPath); return new DiffInfo (baseLocalPath, vi.LocalPath, GenerateDiff (null, ctxt)); } else if ((vi.Status & VersionStatus.ScheduledDelete) != 0) { var ctxt = GetCommitContent (GetHeadCommit (), vi.LocalPath); return new DiffInfo (baseLocalPath, vi.LocalPath, GenerateDiff (ctxt, null)); } else if ((vi.Status & VersionStatus.Modified) != 0 || (vi.Status & VersionStatus.Conflicted) != 0) { var ctxt1 = GetCommitContent (GetHeadCommit (), vi.LocalPath); var ctxt2 = GetFileContent (vi.LocalPath); return new DiffInfo (baseLocalPath, vi.LocalPath, GenerateDiff (ctxt1, ctxt2)); } } catch (Exception ex) { LoggingService.LogError ("Could not get diff for file '" + vi.LocalPath + "'", ex); } return null; */ }
private ChangeSet GetChangeSet(RevSpec id) { var log = Repository.Log(id); return CreateChangeSet(log.SingleOrDefault()); }
public RevisionInfo[] GetRevisions(RevisionId fromChangeset, RevisionId toChangeset) { var from = new RevSpec(fromChangeset.Value); var to = new RevSpec(toChangeset.Value); var command = new LogCommand().WithRevision(RevSpec.Range(from, to)).WithIncludePathActions(); var revisionInfos = _repository.Log(command) .Where(ch => ch.Timestamp >= fromChangeset.Time.Value && ch.Timestamp <= toChangeset.Time.Value) .Select(ch => ch.ToRevisionInfo()) .ToArray(); return revisionInfos; }
/// <summary> /// Open the Tag gui. /// </summary> /// <param name="repository"> /// The <see cref="Repository"/> to synchronize. /// </param> /// <param name="revision"> /// The <see cref="RevSpec"/> of the revision to tag. /// </param> /// <param name="name"> /// The name of the tag. /// </param> /// <param name="command"> /// Any extra options to the tag method, or <c>null</c> for default options. /// </param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="repository"/> is <c>null</c>.</para> /// <para>- or -</para> /// <para><paramref name="revision"/> is <c>null</c>.</para> /// <para>- or -</para> /// <para><paramref name="name"/> is <c>null</c> or empty.</para> /// </exception> /// <exception cref="ArgumentException"> /// <para><see cref="TagGuiCommand.Revision"/> cannot be set before calling this method.</para> /// <para>- or -</para> /// <para><see cref="TagGuiCommand.Name"/> cannot be set before calling this method.</para> /// </exception> /// <remarks> /// This command is only available for the <see cref="GuiClientType.PyQT"/> client type. /// </remarks> public static void TagGui(this Repository repository, RevSpec revision, string name, TagGuiCommand command = null) { if (repository == null) throw new ArgumentNullException("repository"); if (revision == null) throw new ArgumentNullException("revision"); if (StringEx.IsNullOrWhiteSpace(name)) throw new ArgumentNullException("name"); if (command != null && command.Revision != null) throw new ArgumentException("TagGuiCommand.Revision cannot be set before calling this method", "command"); if (command != null && !StringEx.IsNullOrWhiteSpace(command.Name)) throw new ArgumentException("TagGuiCommand.Name cannot be set before calling this method", "command"); command = (command ?? new TagGuiCommand()) .WithRevision(revision) .WithName(name); repository.Execute(command); }
/// <summary> /// Initializes a new instance of the <see cref="BisectResult"/> class. /// </summary> public BisectResult() { _Revision = null; _Done = true; }
private ChangeSet GetChangeSet(RevSpec id) { var log = Enumerable.Empty<Changeset>(); try { log = Repository.Log(id); } catch (MercurialExecutionException e) { // Older Mercurial (e.g. 2.4.1) were returning empty without errors when called with an unknown revision, // but newer versions (e.g. 2.7.1) actually fail here, so account for that possibility so we can run on both if (!e.Message.Contains("unknown revision")) throw; } var changeset = log.SingleOrDefault(); if (changeset != null) { return CreateChangeSet(changeset); } return null; }
public void OperatorOr_ReturnsCorrectExpression() { var r1 = new RevSpec("10"); var r2 = new RevSpec("20"); RevSpec r = r1 || r2; Assert.That(r, Is.EqualTo(new RevSpec("10 or 20"))); }
/// <summary> /// Launch the visual diff tool. /// </summary> /// <param name="repository"> /// The <see cref="Repository"/> to view diffs from. /// </param> /// <param name="revisions"> /// The revision <see cref="RevSpec"/> that identifies the revision or the /// revision range to view a diff of. /// </param> /// <param name="command"> /// Any extra options to the vdiff method, or <c>null</c> for default options. /// </param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="repository"/> is <c>null</c>.</para> /// </exception> /// <exception cref="ArgumentException"> /// <para><see cref="DiffGuiCommand.Revisions"/> cannot be set before calling this method.</para> /// </exception> public static void DiffGui(this Repository repository, RevSpec revisions, DiffGuiCommand command = null) { if (repository == null) throw new ArgumentNullException("repository"); if (revisions == null) throw new ArgumentNullException("revisions"); if (command != null && !StringEx.IsNullOrWhiteSpace(command.Revisions)) throw new ArgumentException("DiffGuiCommand.Revisions cannot be set before calling this method", "command"); command = (command ?? new DiffGuiCommand()) .WithRevisions(revisions); repository.Execute(command); }
private ChangeSet GetChangeSet(RevSpec id) { var log = Repository.Log(id); var changeset = log.SingleOrDefault(); if (changeset != null) { return CreateChangeSet(changeset); } return null; }