Skip to content

Commit

Permalink
Upstream commits (cherry pick to the template from the project)
Browse files Browse the repository at this point in the history
  • Loading branch information
winton committed Nov 9, 2009
1 parent 534cb74 commit e3dea17
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 20 deletions.
3 changes: 1 addition & 2 deletions gemspec.rb
Expand Up @@ -7,13 +7,12 @@
s.homepage = "http://github.com/winton/#{GEM_NAME}" s.homepage = "http://github.com/winton/#{GEM_NAME}"
s.summary = "Project template manager" s.summary = "Project template manager"
# == CONFIGURE == # == CONFIGURE ==
s.add_dependency('httparty', '=0.4.5')
s.executables << GEM_NAME s.executables << GEM_NAME
s.extra_rdoc_files = [ "README.markdown" ] s.extra_rdoc_files = [ "README.markdown" ]
s.files = GEM_FILES.to_a s.files = GEM_FILES.to_a
s.has_rdoc = false s.has_rdoc = false
s.name = GEM_NAME s.name = GEM_NAME
s.platform = Gem::Platform::RUBY s.platform = Gem::Platform::RUBY
s.require_path = "lib" s.require_path = "lib"
s.version = "0.1.0" s.version = "0.1.1"
end end
4 changes: 2 additions & 2 deletions lib/stencil.rb
Expand Up @@ -16,8 +16,8 @@ def initialize(args)
elsif Config.exists?(:projects, path) elsif Config.exists?(:projects, path)


# If upstream commit, merge upstream # If upstream commit, merge upstream
if args.first == '<' if args.first == '^'
Merge.upstream args[1..-1] Merge.upstream *args[1..-1].unshift(name) and return


# If template specified, update config # If template specified, update config
elsif args.first elsif args.first
Expand Down
52 changes: 42 additions & 10 deletions lib/stencil/merge.rb
Expand Up @@ -8,11 +8,9 @@ def project(name, path)
if template if template
template = Config.read[:templates][template.intern] template = Config.read[:templates][template.intern]
if template && File.exists?(template[:path]) if template && File.exists?(template[:path])
origin = Cmd.run template[:path], "git remote show origin" origin = get_origin template[:path]
origin = origin.match(/URL:\s+(\S+)/)[1]
Msg.template_url origin Msg.template_url origin
Cmd.run path, "git remote rm template" add_remote 'template', path, origin
Cmd.run path, "git remote add template #{origin}"
branches = %w(master) if branches.empty? branches = %w(master) if branches.empty?
branches.each do |branch| branches.each do |branch|
Msg.merge_remote_branch branch Msg.merge_remote_branch branch
Expand All @@ -35,19 +33,53 @@ def template(path)
Cmd.run path, "git checkout master" Cmd.run path, "git checkout master"
end 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 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) def progressive(path, branches)
merger = branches.shift merger = branches.shift
mergee = branches.first mergee = branches.first
if merger && mergee if merger && mergee
puts "Merging \"#{merger}\" into \"#{mergee}\"" puts "Merging \"#{merger}\" into \"#{mergee}\""
output = Cmd.run(path, "git checkout #{mergee} && git merge #{merger}") output = Cmd.run path, "git checkout #{mergee}"
if output.downcase.include?('conflict') Msg.error(output) if output.downcase.include?('error')
puts output output = Cmd.run path, "git merge #{merger}"
else Msg.error(output) if output.downcase.include?('conflict')
progressive(path, branches) progressive(path, branches)
end
end end
end end
end end
Expand Down
25 changes: 25 additions & 0 deletions lib/stencil/msg.rb
Expand Up @@ -2,24 +2,49 @@ class Stencil
class Msg class Msg
class <<self class <<self


def cherry_pick(branch, commit)
space
puts "Cherry picked #{commit} to \"#{branch}\""
end

def error(output)
space
puts "Oops:\n#{output}"
exit
end

def is_template_or_project?(name) def is_template_or_project?(name)
space
puts "Is \"#{name}\" a template or a project?" puts "Is \"#{name}\" a template or a project?"
end end


def merge_remote_branch(branch) def merge_remote_branch(branch)
space
puts "Merging remote branch \"#{branch}\"" puts "Merging remote branch \"#{branch}\""
end end


def project_url(url)
space
puts "Found project URL: #{url}"
end

def space
puts ''
end

def specify_template def specify_template
space
puts "Please tell stencil what template you want to receive updates from:" puts "Please tell stencil what template you want to receive updates from:"
puts " stencil TEMPLATE [BRANCH BRANCH ...]" puts " stencil TEMPLATE [BRANCH BRANCH ...]"
end end


def template_not_found(template) def template_not_found(template)
space
puts "Template \"#{template}\" not found." puts "Template \"#{template}\" not found."
end end


def template_url(url) def template_url(url)
space
puts "Found template URL: #{url}" puts "Found template URL: #{url}"
end end
end end
Expand Down
9 changes: 3 additions & 6 deletions stencil.gemspec
Expand Up @@ -2,16 +2,16 @@


Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = %q{stencil} s.name = %q{stencil}
s.version = "0.1.0" s.version = "0.1.1"


s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Winton Welsh"] s.authors = ["Winton Welsh"]
s.date = %q{2009-11-06} s.date = %q{2009-11-09}
s.default_executable = %q{stencil} s.default_executable = %q{stencil}
s.email = %q{mail@wintoni.us} s.email = %q{mail@wintoni.us}
s.executables = ["stencil"] s.executables = ["stencil"]
s.extra_rdoc_files = ["README.markdown"] 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.homepage = %q{http://github.com/winton/stencil}
s.require_paths = ["lib"] s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.5} s.rubygems_version = %q{1.3.5}
Expand All @@ -22,11 +22,8 @@ Gem::Specification.new do |s|
s.specification_version = 3 s.specification_version = 3


if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<httparty>, ["= 0.4.5"])
else else
s.add_dependency(%q<httparty>, ["= 0.4.5"])
end end
else else
s.add_dependency(%q<httparty>, ["= 0.4.5"])
end end
end end

0 comments on commit e3dea17

Please sign in to comment.