Skip to content

Commit

Permalink
Merge pull request #32 from rmm5t/fix-for-clean-builds
Browse files Browse the repository at this point in the history
Backup and restore .git directory during middleman builds
  • Loading branch information
rmm5t committed Feb 16, 2016
2 parents 7806a2a + 632c8c4 commit aee2958
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/middleman-gh-pages/tasks/gh-pages.rake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'fileutils'
require 'tmpdir'

def remote_name
ENV.fetch("REMOTE_NAME", "origin")
Expand All @@ -12,6 +13,15 @@ def nothing_to_commit?
`git status --porcelain`.chomp.empty?
end

def backup_and_restore(dir, file, &block)
yield unless File.exist?(File.join(dir, file))
Dir.mktmpdir do |tmpdir|
mv File.join(dir, file), tmpdir
yield
mv File.join(tmpdir, file), dir
end
end

PROJECT_ROOT = `git rev-parse --show-toplevel`.strip
BUILD_DIR = File.join(PROJECT_ROOT, "build")
GH_PAGES_REF = File.join(BUILD_DIR, ".git/refs/remotes/#{remote_name}/#{branch_name}")
Expand Down Expand Up @@ -65,8 +75,10 @@ end

desc "Compile all files into the build directory"
task :build do
cd PROJECT_ROOT do
sh "bundle exec middleman build --clean"
backup_and_restore(BUILD_DIR, ".git") do
cd PROJECT_ROOT do
sh "bundle exec middleman build --clean"
end
end
end

Expand Down

0 comments on commit aee2958

Please sign in to comment.