Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Do not delete repositories in _site upon build. #556

Closed
wants to merge 2 commits into from

2 participants

@parkr
Owner

This pull request includes the code (with tests) that allows the user to keep repositories that are setup in _site, i.e. they are not deleted from the destination directory upon the execution of Site#cleanup. It covers Git, SVN, and Mercurial. Additionally, a configuration option (keep_repos) was added to allow the user to turn this functionality off if preferred, but it is on by default ("if it (the repo) is there, don't touch it"-kind of reasoning).

@parkr
Owner

This is a different implementation of #337. 337 only includes .git files and has a bug in it.

@cnlpete

+1

@parkr
Owner

Closing to rework the approach. Am going to create a pre-filled String, Jekyll::DEFAULTS['ignore'] which contains a comma-separated list of files and folders to ignore upon the execution of Site#cleanup.

@parkr parkr closed this
@abhiyerra abhiyerra referenced this pull request from a commit in abhiyerra/jekyll
@edeustace edeustace Added a configuration variable: keep_files (default: ['.git']), based…
… on this pull request: jekyll#556
7c800d3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 20, 2012
  1. @parkr
  2. @parkr

    Added proper regular expression for not only the directory but also t…

    parkr authored
    …he files within, albeit not beautifully.
This page is out of date. Refresh to see the latest.
View
4 bin/jekyll
@@ -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
View
1  lib/jekyll.rb
@@ -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,
View
10 lib/jekyll/site.rb
@@ -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
@@ -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
@@ -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
View
17 test/test_site.rb
@@ -180,6 +180,14 @@ 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
@@ -187,6 +195,9 @@ class TestSite < Test::Unit::TestCase
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
@@ -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
Something went wrong with that request. Please try again.