This repository has been archived by the owner on May 18, 2021. It is now read-only.
forked from reed/turbolinks-compatibility
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
44 lines (37 loc) · 1.34 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'nanoc/tasks'
# prompt user for a commit message; default: HEAD commit 1-liner
def commit_message
last_commit = `git log -1 --pretty=format:"%s"`.chomp.strip
last_commit = `Publishing to Turbolinks Compatibility.` if last_commit == ''
print "Enter a commit message (default: '#{last_commit}'): "
STDOUT.flush
mesg = STDIN.gets.chomp.strip
mesg = last_commit if mesg == ''
mesg.gsub(/'/, '')
end
desc "Publish to http://reed.github.io/turbolinks-compatibility"
task :publish => [:clean] do
mesg = commit_message
FileUtils.rm_r('output') if File.exists?('output')
sh "nanoc compile"
ENV['GIT_DIR'] = File.expand_path(`git rev-parse --git-dir`.chomp)
old_sha = `git rev-parse refs/remotes/origin/gh-pages`.chomp
Dir.chdir('output') do
ENV['GIT_INDEX_FILE'] = gif = '/tmp/dev.gh.i'
ENV['GIT_WORK_TREE'] = Dir.pwd
File.unlink(gif) if File.file?(gif)
`git add -A`
tsha = `git write-tree`.strip
puts "Created tree #{tsha}"
if old_sha.size == 40
csha = `git commit-tree #{tsha} -p #{old_sha} -m '#{mesg}'`.strip
else
csha = `git commit-tree #{tsha} -m '#{mesg}'`.strip
end
puts "Created commit #{csha}"
puts `git show #{csha} --stat`
puts "Updating gh-pages from #{old_sha}"
`git update-ref refs/heads/gh-pages #{csha}`
`git push origin gh-pages`
end
end