Merge pull request #8 from benben/git-deploy
Better git deployment. * Remove outdated git gem. * Support git remotes other than "origin". * Use "build" directory as tmp git repo.
This commit is contained in:
commit
95a796ab41
3 changed files with 42 additions and 42 deletions
27
README.md
27
README.md
|
@ -58,42 +58,31 @@ Default is `false`.
|
|||
|
||||
### Step 4b - Git setup
|
||||
|
||||
First be sure that you have already placed your project under revision
|
||||
control using git.
|
||||
|
||||
For example, for the default values of remote="master" and
|
||||
branch="gh-pages", the output of `git branch -a` should look like:
|
||||
|
||||
gh-pages
|
||||
* master
|
||||
remotes/origin/HEAD -> origin/master
|
||||
remotes/origin/gh-pages
|
||||
remotes/origin/master
|
||||
|
||||
This shows that "gh-pages" exists in the remote and local repos. There
|
||||
needs to be at least one commit in "gh-pages" with which to start.
|
||||
|
||||
Edit `config.rb`, and add:
|
||||
|
||||
activate :deploy do |deploy|
|
||||
deploy.method = :git
|
||||
end
|
||||
|
||||
With this default configuration, it will deploy to the "origin/gh-pages" branch of
|
||||
your current repo.
|
||||
|
||||
#### These settings are optional.
|
||||
|
||||
To use a particular remote, add:
|
||||
|
||||
deploy.remote = "some-other-remote-name"
|
||||
|
||||
Default is `origin`. Run `git remote -v` to see a list of possible
|
||||
remotes.
|
||||
Default is `origin`. You can add a remote or a git url.
|
||||
Run `git remote -v` to see a list of possible remotes or add a new one first.
|
||||
If you specify a git url, be sure it ends with '.git'.
|
||||
|
||||
To use a particular branch, add:
|
||||
|
||||
deploy.branch = "some-other-branch-name"
|
||||
|
||||
Default is `gh-pages`. Run `git branch -a` to see a list of possible
|
||||
branches.
|
||||
Default is `gh-pages`. If the branch doesn't exist remote, it will be created
|
||||
for you.
|
||||
|
||||
### Step 4c - FTP setup
|
||||
|
||||
|
|
|
@ -3,8 +3,6 @@ require "middleman-core/cli"
|
|||
require "middleman-deploy/extension"
|
||||
require "middleman-deploy/pkg-info"
|
||||
|
||||
require "git"
|
||||
|
||||
PACKAGE = "#{Middleman::Deploy::PACKAGE}"
|
||||
VERSION = "#{Middleman::Deploy::VERSION}"
|
||||
|
||||
|
@ -126,28 +124,42 @@ EOF
|
|||
|
||||
puts "## Deploying via git to remote=\"#{remote}\" and branch=\"#{branch}\""
|
||||
|
||||
# ensure that the remote branch exists in ENV["MM_ROOT"]
|
||||
orig = Git.open(ENV["MM_ROOT"])
|
||||
# TODO: orig.branch(branch, "#{remote}/#{branch}")
|
||||
|
||||
Dir.mktmpdir do |tmp|
|
||||
# clone ENV["MM_ROOT"] to tmp (ENV["MM_ROOT"] is now "origin")
|
||||
repo = Git.clone(ENV["MM_ROOT"], tmp)
|
||||
repo.checkout("origin/#{branch}", :new_branch => branch)
|
||||
|
||||
# copy ./build/* to tmp
|
||||
FileUtils.cp_r(Dir.glob(File.join(ENV["MM_ROOT"], "build", "*")), tmp)
|
||||
|
||||
# git add and commit in tmp
|
||||
repo.add
|
||||
repo.commit("Automated commit at #{Time.now.utc} by #{PACKAGE} #{VERSION}")
|
||||
|
||||
# push back into ENV["MM_ROOT"]
|
||||
repo.push("origin", branch)
|
||||
#check if remote is not a git url
|
||||
unless remote =~ /\.git$/
|
||||
remote = `git config --get remote.#{remote}.url`.chop
|
||||
end
|
||||
|
||||
orig.push(remote, branch)
|
||||
orig.remote(remote).fetch
|
||||
#if the remote name doesn't exist in the main repo
|
||||
if remote == ''
|
||||
puts "Can't deploy! Please add a remote with the name '#{self.deploy_options.remote}' to your repo."
|
||||
exit
|
||||
end
|
||||
|
||||
Dir.chdir('build') do
|
||||
unless File.exists?('.git')
|
||||
`git init`
|
||||
`git remote add origin #{remote}`
|
||||
else
|
||||
#check if the remote repo has changed
|
||||
unless remote == `git config --get remote.origin.url`.chop
|
||||
`git remote rm origin`
|
||||
`git remote add origin #{remote}`
|
||||
end
|
||||
end
|
||||
|
||||
`git fetch origin`
|
||||
|
||||
#if there is a remote branch with that name, reset to it, otherwise just create a new one
|
||||
if `git branch -r`.split("\n").keep_if{ |r| r =~ Regexp.new(branch,true) }.count > 0
|
||||
`git reset --hard origin/#{branch}`
|
||||
else
|
||||
`git checkout -b #{branch}`
|
||||
end
|
||||
|
||||
`git add -A`
|
||||
`git commit --allow-empty -am 'Automated commit at #{Time.now.utc} by #{PACKAGE} #{VERSION}'`
|
||||
`git push -f origin #{branch}`
|
||||
end
|
||||
end
|
||||
|
||||
def deploy_ftp
|
||||
|
|
|
@ -21,6 +21,5 @@ Gem::Specification.new do |s|
|
|||
s.add_runtime_dependency("middleman-core", [">= 3.0.0"])
|
||||
|
||||
# Additional dependencies
|
||||
s.add_runtime_dependency("git", "~> 1.2.0")
|
||||
s.add_runtime_dependency("ptools")
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue