Merge pull request #876 from imathis/gh-pages-url-parser-fix

Updated URL parser for setup_github_pages. Fixes #868
This commit is contained in:
Brandon Mathis 2012-12-19 21:51:30 -08:00
commit 125ff6d080

View File

@ -382,11 +382,14 @@ task :setup_github_pages, :repo do |t, args|
else else
repo_url = get_stdin("Enter the read/write url for your repository: ") repo_url = get_stdin("Enter the read/write url for your repository: ")
end end
unless repo_url[-4..-1] == ".git"
repo_url << ".git"
end
raise "!! The repo URL that was input was malformed." unless repo_url.match(/https:\/\/github.com\/[^\/]+\/[^\/]+/) or repo_url.match(/git@github.com:[^\/]+\/[^\/]+/) raise "!! The repo URL that was input was malformed." unless repo_url.match(/https:\/\/github.com\/[^\/]+\/[^\/]+/) or repo_url.match(/git@github.com:[^\/]+\/[^\/]+/)
user_match = repo_url.match(/(:([^\/]+)|(github.com\/([^\/]+)))/) user_match = repo_url.match(/(:([^\/]+)|(github.com\/([^\/]+)))/)
user = user_match[2] || user_match[4] user = user_match[2] || user_match[4]
branch = (repo_url.match(/\/[\w-]+.github.com/).nil?) ? 'gh-pages' : 'master' branch = (repo_url.match(/\/[\w-]+.github.com/).nil?) ? 'gh-pages' : 'master'
project = (branch == 'gh-pages') ? repo_url.match(/\/([^\.]+)/)[1] : '' project = (branch == 'gh-pages') ? repo_url.match(/\/(.+)(\.git)/)[1] : ''
url = "http://#{user}.github.com" url = "http://#{user}.github.com"
url += "/#{project}" unless project == '' url += "/#{project}" unless project == ''
unless `git remote -v`.match(/origin.+?octopress.git/).nil? unless `git remote -v`.match(/origin.+?octopress.git/).nil?