From e3dea1740d0ff1d62589cde32b682334f9f9c198 Mon Sep 17 00:00:00 2001 From: winton Date: Mon, 9 Nov 2009 13:50:45 -0800 Subject: [PATCH] Upstream commits (cherry pick to the template from the project) --- gemspec.rb | 3 +-- lib/stencil.rb | 4 ++-- lib/stencil/merge.rb | 52 +++++++++++++++++++++++++++++++++++--------- lib/stencil/msg.rb | 25 +++++++++++++++++++++ stencil.gemspec | 9 +++----- 5 files changed, 73 insertions(+), 20 deletions(-) diff --git a/gemspec.rb b/gemspec.rb index fbcccae..1448dc1 100644 --- a/gemspec.rb +++ b/gemspec.rb @@ -7,7 +7,6 @@ s.homepage = "http://github.com/winton/#{GEM_NAME}" s.summary = "Project template manager" # == CONFIGURE == - s.add_dependency('httparty', '=0.4.5') s.executables << GEM_NAME s.extra_rdoc_files = [ "README.markdown" ] s.files = GEM_FILES.to_a @@ -15,5 +14,5 @@ s.name = GEM_NAME s.platform = Gem::Platform::RUBY s.require_path = "lib" - s.version = "0.1.0" + s.version = "0.1.1" end diff --git a/lib/stencil.rb b/lib/stencil.rb index 057b512..1ac363c 100644 --- a/lib/stencil.rb +++ b/lib/stencil.rb @@ -16,8 +16,8 @@ def initialize(args) elsif Config.exists?(:projects, path) # If upstream commit, merge upstream - if args.first == '<' - Merge.upstream args[1..-1] + if args.first == '^' + Merge.upstream *args[1..-1].unshift(name) and return # If template specified, update config elsif args.first diff --git a/lib/stencil/merge.rb b/lib/stencil/merge.rb index 1b6bb1e..9b40bab 100644 --- a/lib/stencil/merge.rb +++ b/lib/stencil/merge.rb @@ -8,11 +8,9 @@ def project(name, path) if template template = Config.read[:templates][template.intern] if template && File.exists?(template[:path]) - origin = Cmd.run template[:path], "git remote show origin" - origin = origin.match(/URL:\s+(\S+)/)[1] + origin = get_origin template[:path] Msg.template_url origin - Cmd.run path, "git remote rm template" - Cmd.run path, "git remote add template #{origin}" + add_remote 'template', path, origin branches = %w(master) if branches.empty? branches.each do |branch| Msg.merge_remote_branch branch @@ -35,19 +33,53 @@ def template(path) Cmd.run path, "git checkout master" end + def upstream(name, commit, branches=[]) + project = Config.read[:projects][name] + branch = Cmd.run(project[:path], "git branch").split + branch = branch[branch.index('*') + 1] + + template = Config.read[:templates][project[:template].intern] + path = template[:path] + + origin = get_origin project[:path] + Msg.project_url origin + add_remote 'project', path, origin + Cmd.run path, "git fetch project" + + branches = %w(master) if branches.empty? + branches.each do |branch| + output = Cmd.run path, "git checkout #{branch}" + Msg.error(output) if output.downcase.include?('error') + Msg.cherry_pick branch, commit + output = Cmd.run path, "git cherry-pick #{commit}" + Msg.error(output) if output.downcase.include?('fatal') + end + end + private + def add_remote(name, path, url) + if Cmd.run(path, "git remote").split.include?(name) + Cmd.run path, "git remote rm #{name}" + end + Cmd.run path, "git remote add #{name} #{url}" + end + + def get_origin(path) + origin = Cmd.run path, "git remote show origin" + origin.match(/URL:\s+(\S+)/)[1] + end + def progressive(path, branches) merger = branches.shift mergee = branches.first if merger && mergee puts "Merging \"#{merger}\" into \"#{mergee}\"" - output = Cmd.run(path, "git checkout #{mergee} && git merge #{merger}") - if output.downcase.include?('conflict') - puts output - else - progressive(path, branches) - end + output = Cmd.run path, "git checkout #{mergee}" + Msg.error(output) if output.downcase.include?('error') + output = Cmd.run path, "git merge #{merger}" + Msg.error(output) if output.downcase.include?('conflict') + progressive(path, branches) end end end diff --git a/lib/stencil/msg.rb b/lib/stencil/msg.rb index cff9478..6376b2f 100644 --- a/lib/stencil/msg.rb +++ b/lib/stencil/msg.rb @@ -2,24 +2,49 @@ class Stencil class Msg class <= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Winton Welsh"] - s.date = %q{2009-11-06} + s.date = %q{2009-11-09} s.default_executable = %q{stencil} s.email = %q{mail@wintoni.us} s.executables = ["stencil"] s.extra_rdoc_files = ["README.markdown"] - s.files = ["bin", "bin/stencil", "gemspec.rb", "lib", "lib/stencil", "lib/stencil/branches.rb", "lib/stencil/cmd.rb", "lib/stencil/config.rb", "lib/stencil/hash.rb", "lib/stencil/merge.rb", "lib/stencil/msg.rb", "lib/stencil.rb", "MIT-LICENSE", "Rakefile", "README.markdown", "spec", "spec/spec.opts", "spec/spec_helper.rb"] + s.files = ["bin", "bin/stencil", "gemspec.rb", "lib", "lib/stencil", "lib/stencil/branches.rb", "lib/stencil/cmd.rb", "lib/stencil/config.rb", "lib/stencil/hash.rb", "lib/stencil/merge.rb", "lib/stencil/msg.rb", "lib/stencil.rb", "MIT-LICENSE", "Rakefile", "README.markdown", "spec", "spec/spec.opts", "spec/spec_helper.rb", "stencil.gemspec"] s.homepage = %q{http://github.com/winton/stencil} s.require_paths = ["lib"] s.rubygems_version = %q{1.3.5} @@ -22,11 +22,8 @@ Gem::Specification.new do |s| s.specification_version = 3 if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then - s.add_runtime_dependency(%q, ["= 0.4.5"]) else - s.add_dependency(%q, ["= 0.4.5"]) end else - s.add_dependency(%q, ["= 0.4.5"]) end end