Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not delete repositories in _site upon build. #556

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bin/jekyll
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ opts = OptionParser.new do |opts|
options['url'] = url
end

opts.on("--keep-repos FALSE", "Whether to delete Git, SVN or Mercurial repository in site destination") do
options['keep_repos'] = false
end

opts.on("--version", "Display current version") do
puts "Jekyll " + Jekyll::VERSION
exit 0
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module Jekyll
'source' => Dir.pwd,
'destination' => File.join(Dir.pwd, '_site'),
'plugins' => File.join(Dir.pwd, '_plugins'),
'keep_repos' => true,

'future' => true,
'lsi' => false,
Expand Down
10 changes: 8 additions & 2 deletions lib/jekyll/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module Jekyll
class Site
attr_accessor :config, :layouts, :posts, :pages, :static_files,
:categories, :exclude, :include, :source, :dest, :lsi, :pygments,
:permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts
:permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts,
:keep_repos

attr_accessor :converters, :generators

Expand All @@ -26,6 +27,7 @@ def initialize(config)
self.include = config['include'] || []
self.future = config['future']
self.limit_posts = config['limit_posts'] || nil
self.keep_repos = config['keep_repos']

self.reset
self.setup
Expand Down Expand Up @@ -217,7 +219,11 @@ def cleanup
# all files and directories in destination, including hidden ones
dest_files = Set.new
Dir.glob(File.join(self.dest, "**", "*"), File::FNM_DOTMATCH) do |file|
dest_files << file unless file =~ /\/\.{1,2}$/
if self.keep_repos
dest_files << file unless file =~ /\/\.{1,2}$/ or file =~ /\/\.(git|hg|svn)/
else
dest_files << file unless file =~ /\/\.{1,2}$/
end
end

# files to be written
Expand Down
17 changes: 17 additions & 0 deletions test/test_site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,24 @@ class TestSite < Test::Unit::TestCase
File.open(dest_dir('qux/obsolete.html'), 'w')
# empty directory
FileUtils.mkdir(dest_dir('quux'))
# repositories
FileUtils.mkdir(dest_dir('.git'))
FileUtils.mkdir(dest_dir('.svn'))
FileUtils.mkdir(dest_dir('.hg'))
# single file in repository
File.open(dest_dir('.git/HEAD'), 'w')
File.open(dest_dir('.svn/HEAD'), 'w')
File.open(dest_dir('.hg/HEAD'), 'w')
end

teardown do
FileUtils.rm_f(dest_dir('.htpasswd'))
FileUtils.rm_f(dest_dir('obsolete.html'))
FileUtils.rm_rf(dest_dir('qux'))
FileUtils.rm_f(dest_dir('quux'))
FileUtils.rm_rf(dest_dir('.git'))
FileUtils.rm_rf(dest_dir('.svn'))
FileUtils.rm_rf(dest_dir('.hg'))
end

should 'remove orphaned files in destination' do
Expand All @@ -195,6 +206,12 @@ class TestSite < Test::Unit::TestCase
assert !File.exist?(dest_dir('obsolete.html'))
assert !File.exist?(dest_dir('qux'))
assert !File.exist?(dest_dir('quux'))
assert File.exist?(dest_dir('.git'))
assert File.exist?(dest_dir('.svn'))
assert File.exist?(dest_dir('.hg'))
assert File.exist?(dest_dir('.git/HEAD'))
assert File.exist?(dest_dir('.svn/HEAD'))
assert File.exist?(dest_dir('.hg/HEAD'))
end

end
Expand Down