From 65084c9ee40cca910518a00aa4a6a599cfc339b6 Mon Sep 17 00:00:00 2001 From: Linus Sellberg Date: Wed, 19 Jan 2022 12:55:50 +0100 Subject: [PATCH 1/2] Compiler specs: Don't fail if user has a different default git branch. It is fairly common to define "main" as the default branch name, and specs should not fail if that is configured. Therefore a new branch is checked out after initializing a new git repo for the specs that are dependent on the branch name. --- .../compiler/crystal/tools/doc/project_info_spec.cr | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/spec/compiler/crystal/tools/doc/project_info_spec.cr b/spec/compiler/crystal/tools/doc/project_info_spec.cr index a5a44cb9476d..93e0dd1dd933 100644 --- a/spec/compiler/crystal/tools/doc/project_info_spec.cr +++ b/spec/compiler/crystal/tools/doc/project_info_spec.cr @@ -92,11 +92,12 @@ describe Crystal::Doc::ProjectInfo do it "git non-tagged commit" do run_git "init" + run_git "checkout -b a_branch" run_git "add shard.yml" run_git "commit -m \"Initial commit\" --no-gpg-sign" commit_sha = `git rev-parse HEAD`.chomp - assert_with_defaults(ProjectInfo.new(nil, nil), ProjectInfo.new("foo", "master", refname: commit_sha)) + assert_with_defaults(ProjectInfo.new(nil, nil), ProjectInfo.new("foo", "a_branch", refname: commit_sha)) assert_with_defaults(ProjectInfo.new(nil, "1.1"), ProjectInfo.new("foo", "1.1", refname: commit_sha)) assert_with_defaults(ProjectInfo.new("bar", "2.0"), ProjectInfo.new("bar", "2.0", refname: commit_sha)) assert_with_defaults(ProjectInfo.new("bar", "2.0", refname: "12345"), ProjectInfo.new("bar", "2.0", refname: "12345")) @@ -104,11 +105,12 @@ describe Crystal::Doc::ProjectInfo do it "git non-tagged commit dirty" do run_git "init" + run_git "checkout -b a_branch" run_git "add shard.yml" run_git "commit -m \"Initial commit\" --no-gpg-sign" File.write("shard.yml", "\n", mode: "a") - assert_with_defaults(ProjectInfo.new(nil, nil), ProjectInfo.new("foo", "master-dev", refname: nil)) + assert_with_defaults(ProjectInfo.new(nil, nil), ProjectInfo.new("foo", "a_branch-dev", refname: nil)) assert_with_defaults(ProjectInfo.new(nil, "1.1"), ProjectInfo.new("foo", "1.1", refname: nil)) assert_with_defaults(ProjectInfo.new("bar", "2.0"), ProjectInfo.new("bar", "2.0", refname: nil)) end @@ -145,22 +147,23 @@ describe Crystal::Doc::ProjectInfo do # Empty git directory run_git "init" + run_git "checkout -b original_branch" ProjectInfo.find_git_version.should be_nil # Non-tagged commit File.write("file.txt", "foo") run_git "add file.txt" run_git "commit -m \"Initial commit\" --no-gpg-sign" - ProjectInfo.find_git_version.should eq "master" + ProjectInfo.find_git_version.should eq "original_branch" # Other branch run_git "checkout -b foo" ProjectInfo.find_git_version.should eq "foo" # Non-tagged commit, dirty workdir - run_git "checkout master" + run_git "checkout original_branch" File.write("file.txt", "bar") - ProjectInfo.find_git_version.should eq "master-dev" + ProjectInfo.find_git_version.should eq "original_branch-dev" run_git "checkout -- ." From 5d9aed4607f95e5f85d495c8cf498c92e431d17a Mon Sep 17 00:00:00 2001 From: Linus Sellberg Date: Sun, 23 Jan 2022 11:30:37 +0100 Subject: [PATCH 2/2] Go back to using master. --- .../crystal/tools/doc/project_info_spec.cr | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/compiler/crystal/tools/doc/project_info_spec.cr b/spec/compiler/crystal/tools/doc/project_info_spec.cr index 93e0dd1dd933..9e220e4e3fc3 100644 --- a/spec/compiler/crystal/tools/doc/project_info_spec.cr +++ b/spec/compiler/crystal/tools/doc/project_info_spec.cr @@ -92,12 +92,12 @@ describe Crystal::Doc::ProjectInfo do it "git non-tagged commit" do run_git "init" - run_git "checkout -b a_branch" + run_git "checkout -B master" run_git "add shard.yml" run_git "commit -m \"Initial commit\" --no-gpg-sign" commit_sha = `git rev-parse HEAD`.chomp - assert_with_defaults(ProjectInfo.new(nil, nil), ProjectInfo.new("foo", "a_branch", refname: commit_sha)) + assert_with_defaults(ProjectInfo.new(nil, nil), ProjectInfo.new("foo", "master", refname: commit_sha)) assert_with_defaults(ProjectInfo.new(nil, "1.1"), ProjectInfo.new("foo", "1.1", refname: commit_sha)) assert_with_defaults(ProjectInfo.new("bar", "2.0"), ProjectInfo.new("bar", "2.0", refname: commit_sha)) assert_with_defaults(ProjectInfo.new("bar", "2.0", refname: "12345"), ProjectInfo.new("bar", "2.0", refname: "12345")) @@ -105,12 +105,12 @@ describe Crystal::Doc::ProjectInfo do it "git non-tagged commit dirty" do run_git "init" - run_git "checkout -b a_branch" + run_git "checkout -B master" run_git "add shard.yml" run_git "commit -m \"Initial commit\" --no-gpg-sign" File.write("shard.yml", "\n", mode: "a") - assert_with_defaults(ProjectInfo.new(nil, nil), ProjectInfo.new("foo", "a_branch-dev", refname: nil)) + assert_with_defaults(ProjectInfo.new(nil, nil), ProjectInfo.new("foo", "master-dev", refname: nil)) assert_with_defaults(ProjectInfo.new(nil, "1.1"), ProjectInfo.new("foo", "1.1", refname: nil)) assert_with_defaults(ProjectInfo.new("bar", "2.0"), ProjectInfo.new("bar", "2.0", refname: nil)) end @@ -147,23 +147,23 @@ describe Crystal::Doc::ProjectInfo do # Empty git directory run_git "init" - run_git "checkout -b original_branch" + run_git "checkout -B master" ProjectInfo.find_git_version.should be_nil # Non-tagged commit File.write("file.txt", "foo") run_git "add file.txt" run_git "commit -m \"Initial commit\" --no-gpg-sign" - ProjectInfo.find_git_version.should eq "original_branch" + ProjectInfo.find_git_version.should eq "master" # Other branch run_git "checkout -b foo" ProjectInfo.find_git_version.should eq "foo" # Non-tagged commit, dirty workdir - run_git "checkout original_branch" + run_git "checkout master" File.write("file.txt", "bar") - ProjectInfo.find_git_version.should eq "original_branch-dev" + ProjectInfo.find_git_version.should eq "master-dev" run_git "checkout -- ."