public void ByBranch_WithNameSurroundedBySpaces_ReturnsTrimmedName() { string output = RevSpec.ByBranch(" stable ").ToString(); const string expected = "branch('stable')"; Assert.That(output, Is.EqualTo(expected)); }
public void ByBranch_ForVariousTestCases_ProducesCorrectRevisionSpecification(string input, string expected) { RevSpec rev = RevSpec.ByBranch(input); string output = rev.ToString(); Assert.That(output, Is.EqualTo(expected)); }
/// <inheritdoc /> public ICommit GetBranchHead(string branchName) { var heads = _repository.Heads(new HeadsCommand() .WithBranchRevision(RevSpec.ByBranch(branchName))); return((HgCommit)heads.First()); }
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); } }
/// <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)); }
public void HgMerge_ShouldFailIfMergeConflict() { var path = Repository.Path; var context = new FakeCakeContext(); context.HgInit(path); var repository = context.Hg(Repository.Path); //default branch File.WriteAllText(path + "/dummy.txt", "123"); context.HgCommit(path, "Initial commit"); var firstCommit = context.HgTip(path); File.WriteAllText(path + "/dummy.txt", "213"); context.HgCommit(path, "Dummy commit"); var defaultCommit = context.HgTip(path); repository.Update(firstCommit.Hash); //dev branch repository.Branch("dev"); File.WriteAllText(path + "/dummy.txt", "111"); context.HgCommit(path, "dev commit"); var devCommit = context.HgTip(path); //back to default repository.Update("default"); //merge var result = context.HgMerge(path, "dev"); //check if merge was not performed var currentCommit = repository.Log(RevSpec.ByBranch("default").Max).First(); Assert.Multiple(() => { Assert.That(result, Is.EqualTo(MergeResult.UnresolvedFiles)); Assert.That(repository.Status().Where(s => s.State == FileState.Modified).Count(), Is.EqualTo(0)); Assert.That(currentCommit.Hash, Is.EqualTo(defaultCommit.Hash)); }); }
public void ByBranch_WithEmptyName_ThrowsArgumentNullException() { Assert.Throws <ArgumentNullException>(() => RevSpec.ByBranch(string.Empty)); }
public void ByBranch_WithWhitespaceName_ThrowsArgumentNullException() { Assert.Throws <ArgumentNullException>(() => RevSpec.ByBranch(" \t \n \r ")); }
public void ByBranch_WithNullName_ThrowsArgumentNullException() { Assert.Throws <ArgumentNullException>(() => RevSpec.ByBranch(null)); }
/// <summary> /// Creates a <see cref="HgLogQuery"/> that finds tagged commits that belongs to the named branch. /// </summary> /// <param name="name">Branch name.</param> public HgLogQuery TaggedBranchCommits(string name) { return(RevSpec.ByBranch(name) & RevSpec.Tagged()); }