-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1604 from Shopify/uk-add-gitattributes
Start generating `.gitattributes` file for generated and vendored RBI files
- Loading branch information
Showing
9 changed files
with
146 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ def execute | |
end | ||
|
||
puts | ||
ensure | ||
GitAttributes.create_generated_attribute_file(@outpath) | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
class GitAttributes | ||
class << self | ||
extend T::Sig | ||
|
||
sig { params(path: Pathname).void } | ||
def create_generated_attribute_file(path) | ||
create_gitattributes_file(path, <<~CONTENT) | ||
**/*.rbi linguist-generated=true | ||
CONTENT | ||
end | ||
|
||
sig { params(path: Pathname).void } | ||
def create_vendored_attribute_file(path) | ||
create_gitattributes_file(path, <<~CONTENT) | ||
**/*.rbi linguist-vendored=true | ||
CONTENT | ||
end | ||
|
||
private | ||
|
||
sig { params(path: Pathname, content: String).void } | ||
def create_gitattributes_file(path, content) | ||
# We don't want to start creating folders, just to write | ||
# the `.gitattributes` file. So, if the folder doesn't | ||
# exist, we just return. | ||
return unless path.exist? | ||
|
||
File.write(path.join(".gitattributes"), content) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,6 +224,52 @@ class << self | |
project.remove!("config/application.rb") | ||
end | ||
|
||
it "must generate a .gitattributes file in the output folder" do | ||
foo = mock_gem("foo", "0.0.1") do | ||
write("lib/foo.rb", FOO_RB) | ||
end | ||
|
||
@project.require_mock_gem(foo) | ||
@project.bundle_install | ||
result = @project.tapioca("gem foo --outdir output") | ||
|
||
assert_stdout_includes(result, <<~OUT) | ||
Compiled foo | ||
OUT | ||
|
||
assert_empty_stderr(result) | ||
assert_success_status(result) | ||
|
||
assert_project_file_equal("output/.gitattributes", <<~CONTENT) | ||
**/*.rbi linguist-generated=true | ||
CONTENT | ||
ensure | ||
@project.remove("output") | ||
end | ||
|
||
it "must not generate a .gitattributes file if the output folder is not created" do | ||
foo = mock_gem("foo", "0.0.1") do | ||
write("lib/foo.rb", FOO_RB) | ||
end | ||
|
||
@project.require_mock_gem(foo) | ||
@project.bundle_install | ||
|
||
# Generate for `foo` but exclude it as well, so that we don't create the output folder | ||
result = @project.tapioca("gem foo --outdir output --exclude foo") | ||
|
||
assert_stdout_includes(result, <<~OUT) | ||
Nothing to do. | ||
OUT | ||
|
||
assert_empty_stderr(result) | ||
assert_success_status(result) | ||
|
||
refute_project_file_exist("output/.gitattributes") | ||
ensure | ||
@project.remove("output") | ||
end | ||
|
||
it "must generate a single gem RBI" do | ||
foo = mock_gem("foo", "0.0.1") do | ||
write!("lib/foo.rb", FOO_RB) | ||
|
@@ -1638,6 +1684,20 @@ def baz; end | |
@project.remove!("../gems") | ||
end | ||
|
||
it "must generate a .gitattributes file in the output folder" do | ||
result = @project.tapioca("gem --outdir output") | ||
|
||
assert_stdout_includes(result, "create output/[email protected]") | ||
assert_empty_stderr(result) | ||
assert_success_status(result) | ||
|
||
assert_project_file_equal("output/.gitattributes", <<~CONTENT) | ||
**/*.rbi linguist-generated=true | ||
CONTENT | ||
ensure | ||
@project.remove("output") | ||
end | ||
|
||
it "must perform no operations if everything is up-to-date" do | ||
@project.write!("sorbet/rbi/gems/[email protected]") | ||
@project.write!("sorbet/rbi/gems/[email protected]") | ||
|