Skip to content

Commit

Permalink
refactor: Simplify setup of git repositories for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Crown0815 committed Jan 3, 2024
1 parent 98a90a3 commit 7d17d56
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,21 @@ public static void Tag(this GitObject target, string name)
target.Repository().Tags.Add(name, target);
}

public static Branch CreateAndCheckoutBranch(this IRepository r, string id)
{
var branch = r.CreateBranch(id);
r.Checkout(id);
return branch;
}

public static void Checkout(this IRepository r, string id)
{
Commands.Checkout(r, id);
}

public static void Checkout(this IRepository r, GitCommit commit)
public static void Checkout(this IRepository r, Branch branch)
{
Commands.Checkout(r, commit);
Commands.Checkout(r, branch.FriendlyName);
}

public static GitCommit Merge(this Repository r, Branch branch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace ConventionalChangelog.Unit.Tests.Acceptance;

public class The_changelog_from_a_git_repository_using_conventional_commits : GitUsingTestsBase
{
private const string _defaultBranch = "master";
private static string Version(string version) => $"v{version}";

[Fact]
Expand Down Expand Up @@ -109,18 +110,17 @@ public void and_multiple_version_tags_on_the_same_commit_contains_all_commits_af
public void only_considers_commits_from_the_currently_checked_out_branch()
{
var root = Repository.Commit(Irrelevant, "Initial Commit");
Repository.CreateBranch("develop");
Repository.Checkout("develop");
var develop = Repository.CreateAndCheckoutBranch("develop");
Repository.Commit(Feature, 3).Tag(Version("0.9.0-alpha.1"));
Repository.Commit(Feature, 4);
var end = Repository.Commit(Feature, 5);
Repository.Commit(Feature, 5);

Repository.CreateBranch("release/1.0.0", root);
Repository.Checkout("release/1.0.0");
Repository.Commit(Feature, 1).Tag(Version("1.0.0-beta.1"));
Repository.Commit(Feature, 2);

Repository.Checkout(end);
Repository.Checkout(develop);

Repository.Should().HaveChangelogMatching(A.Changelog.WithGroup(Feature, 5, 4));
}
Expand All @@ -133,7 +133,7 @@ public void when_encountering_merge_commits_ignores_version_tags_on_merged_branc
Repository.Checkout("develop");
Repository.Commit(Feature, 1).Tag(Version("v0.1.0-alpha.1"));
Repository.Commit(Feature, 2).Tag(Version("0.1.0-alpha.2"));
Repository.Checkout("master");
Repository.Checkout(_defaultBranch);
Repository.Merge(develop);

Repository.Should().HaveChangelogMatching(A.Changelog.WithGroup(Feature, 2, 1));
Expand All @@ -147,13 +147,13 @@ public void when_encountering_merge_commits_considers_version_tags_on_merged_com
Repository.Checkout("develop");
Repository.Commit(Feature, 1).Tag(Version("0.1.0-alpha.1"));
Repository.Commit(Feature, 2).Tag(Version("0.1.0-alpha.2"));
Repository.Checkout("master");
Repository.Checkout(_defaultBranch);
Repository.Merge(develop).Tag(Version("0.1.0"));

Repository.Checkout("develop");
Repository.Commit(Feature, 3).Tag(Version("0.2.0-alpha.1"));
Repository.Commit(Feature, 4).Tag(Version("0.2.0-alpha.2"));
Repository.Checkout("master");
Repository.Checkout(_defaultBranch);
Repository.Merge(develop);

Repository.Should().HaveChangelogMatching(A.Changelog.WithGroup(Feature, 4, 3));
Expand Down

0 comments on commit 7d17d56

Please sign in to comment.