Skip to content
Browse files

Upstream commits (cherry pick to the template from the project)

  • Loading branch information...
1 parent 534cb74 commit e3dea1740d0ff1d62589cde32b682334f9f9c198 @winton committed Nov 9, 2009
Showing with 73 additions and 20 deletions.
  1. +1 −2 gemspec.rb
  2. +2 −2 lib/stencil.rb
  3. +42 −10 lib/stencil/merge.rb
  4. +25 −0 lib/stencil/msg.rb
  5. +3 −6 stencil.gemspec
View
3 gemspec.rb
@@ -7,13 +7,12 @@
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
s.has_rdoc = false
s.name = GEM_NAME
s.platform = Gem::Platform::RUBY
s.require_path = "lib"
- s.version = "0.1.0"
+ s.version = "0.1.1"
end
View
4 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
View
52 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
View
25 lib/stencil/msg.rb
@@ -2,24 +2,49 @@ class Stencil
class Msg
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)
+ space
puts "Is \"#{name}\" a template or a project?"
end
def merge_remote_branch(branch)
+ space
puts "Merging remote branch \"#{branch}\""
end
+ def project_url(url)
+ space
+ puts "Found project URL: #{url}"
+ end
+
+ def space
+ puts ''
+ end
+
def specify_template
+ space
puts "Please tell stencil what template you want to receive updates from:"
puts " stencil TEMPLATE [BRANCH BRANCH ...]"
end
def template_not_found(template)
+ space
puts "Template \"#{template}\" not found."
end
def template_url(url)
+ space
puts "Found template URL: #{url}"
end
end
View
9 stencil.gemspec
@@ -2,16 +2,16 @@
Gem::Specification.new do |s|
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.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<httparty>, ["= 0.4.5"])
else
- s.add_dependency(%q<httparty>, ["= 0.4.5"])
end
else
- s.add_dependency(%q<httparty>, ["= 0.4.5"])
end
end

0 comments on commit e3dea17

Please sign in to comment.
Something went wrong with that request. Please try again.