Skip to content

Commit

Permalink
eradicate last use of from gitrepo
Browse files Browse the repository at this point in the history
  • Loading branch information
bronson committed Nov 1, 2011
1 parent 0bf3768 commit e230456
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 39 deletions.
55 changes: 22 additions & 33 deletions lib/gitrepo.rb
@@ -1,6 +1,5 @@
# interface for working on git repos, insulates app from underlying implementation

# todo: only call git via array so no shell interp issues
# todo: make a way for caller to tell GitRepo to indent all log messages?

require 'gitrb'
Expand All @@ -20,10 +19,9 @@ def initialize opts

if opts[:clone]
retryable(:task => "cloning #{opts[:clone]}") do
# todo: add support for :bare
bare = '--bare' if opts[:bare]
output = `git clone #{opts[:clone]} #{opts[:root]} #{bare} 2>&1`
raise GitError.new("git clone failed: #{output}") unless $?.success?
args = [opts[:clone], opts[:root]]
args.push '--bare' if opts[:bare]
git_exec :clone, *args
end
end

Expand All @@ -40,25 +38,29 @@ def root
@root
end

def git *args
def git_exec *args
args = args.map { |a| a.to_s }
Dir.chdir(@root) do
out = IO.popen('-', 'r') do |io|
if io
# parent, read the git output
block_given? ? yield(io) : io.read
else
STDERR.reopen STDOUT
exec 'git', *args
end
out = IO.popen('-', 'r') do |io|
if io
# parent, read the git output
block_given? ? yield(io) : io.read
else
STDERR.reopen STDOUT
exec 'git', *args
end
end

if $?.exitstatus > 0
# return '' if $?.exitstatus == 1 && out == ''
raise GitError.new("git #{args.join(' ')}: #{out}")
end
if $?.exitstatus > 0
# return '' if $?.exitstatus == 1 && out == ''
raise GitError.new("git #{args.join(' ')}: #{out}")
end

out
end

out
def git *args
Dir.chdir(@root) do
git_exec *args
end
end

Expand All @@ -71,19 +73,6 @@ def remote_remove name
end


# todo: get rid of this call, should be regular git add / git commit
def commit_all message
Dir.chdir(@root) {
output = `git commit -a -m '#{message}' 2>&1`
if output =~ /nothing to commit/
puts " no changes to generated files"
else
raise GitError.new("git commit failed: #{output}") unless $?.success?
end
}
end


def pull *args
# Can we tell the difference between a network error, which we want to retry,
# and a merge error, which we want to fail immediately?
Expand Down
16 changes: 10 additions & 6 deletions scraper
Expand Up @@ -505,7 +505,7 @@ def generate_doc_files doc_dir
end
end

return files.keys.map { |name| "api/#{name}" }
return files.keys.map { |name| "#{doc_dir}/api/#{name}" }
end


Expand All @@ -524,8 +524,12 @@ def generate_docs
site.pull 'vim-scripts', 'master'

updated_docs = generate_doc_files doc_dir
# todo: get rid of commit_all, only add and commit updated_docs
site.commit_all 'new scrape' if updated_docs
if updated_docs
author = { :name => $vimscripts_name, :email => $vimscripts_email }
site.commit('new scrape', author) do |commit|
updated_docs.each { |file| commit.add file, File.read(file) }
end
end

site.push 'origin', 'master'
end
Expand Down Expand Up @@ -1203,9 +1207,9 @@ end

def check_for_readme_file commit
# we drop a README file into each repo. don't want to conflict with one already there.
commit.entries.each do |name, value|
commit.entries.each do |name|
if name =~ /^README$/i
raise "already have a readme.orig!" if commit.entries.find { |n,v| n =~ /^readme\.orig$/i }
raise "already have a readme.orig!" if commit.entries.find { |n| n =~ /^readme\.orig$/i }
commit.add name+'.orig', commit.remove(name)
end
end
Expand Down Expand Up @@ -1260,7 +1264,7 @@ def store_versions_in_repo repo, script

author_name, author_email = fix_email_address(version['author'])
author = { :name => author_name, :email => author_email,
:date => Time.new(*version['date'].split('-'), 0, 0, 0, 0)) }
:date => Time.new(*version['date'].split('-'), 0, 0, 0, 0) }

catch :corrupt do
puts " adding #{version['filename']} #{version['date']} #{script_version(version)} to branch #{branch}"
Expand Down

0 comments on commit e230456

Please sign in to comment.