Skip to content

Commit 9d8354c

Browse files
committed
Merge pull request rails#14447 from Houdini/gitignore
Skip sqlite3 files in .gitignore if no sqlite3 in app
2 parents 8bd2912 + f42c7ee commit 9d8354c

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

railties/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Remove sqlite3 lines from `.gitignore` if the application is not using sqlite3.
2+
3+
*Dmitrii Golub*
4+
15
* Add public API to register new extensions for `rake notes`.
26

37
Example:

railties/lib/rails/generators/app_base.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ def comment_if(value)
172172
options[value] ? '# ' : ''
173173
end
174174

175+
def sqlite3?
176+
!options[:skip_active_record] && options[:database] == 'sqlite3'
177+
end
178+
175179
class GemfileEntry < Struct.new(:name, :version, :comment, :options, :commented_out)
176180
def initialize(name, version, comment, options = {}, commented_out = false)
177181
super

railties/lib/rails/generators/rails/app/app_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def configru
5050
end
5151

5252
def gitignore
53-
copy_file "gitignore", ".gitignore"
53+
template "gitignore", ".gitignore"
5454
end
5555

5656
def app

railties/lib/rails/generators/rails/app/templates/gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
# Ignore bundler config.
88
/.bundle
99

10+
<% if sqlite3? -%>
1011
# Ignore the default SQLite database.
1112
/db/*.sqlite3
1213
/db/*.sqlite3-journal
1314

15+
<% end -%>
1416
# Ignore all logfiles and tempfiles.
1517
/log/*.log
1618
/tmp

railties/test/generators/app_generator_test.rb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,31 @@ def test_skip_spring
408408
end
409409
end
410410

411-
protected
411+
def test_gitignore_when_sqlite3
412+
run_generator
413+
414+
assert_file '.gitignore' do |content|
415+
assert_match(/sqlite3/, content)
416+
end
417+
end
418+
419+
def test_gitignore_when_no_active_record
420+
run_generator [destination_root, '--skip-active-record']
421+
422+
assert_file '.gitignore' do |content|
423+
assert_no_match(/sqlite3/, content)
424+
end
425+
end
426+
427+
def test_gitignore_when_non_sqlite3_db
428+
run_generator([destination_root, "-d", "mysql"])
429+
430+
assert_file '.gitignore' do |content|
431+
assert_no_match(/sqlite3/, content)
432+
end
433+
end
434+
435+
protected
412436

413437
def action(*args, &block)
414438
silence(:stdout) { generator.send(*args, &block) }

0 commit comments

Comments
 (0)