stencil 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/gemspec.rb CHANGED
@@ -7,7 +7,6 @@ GEM_SPEC = Gem::Specification.new do |s|
7
7
  s.homepage = "http://github.com/winton/#{GEM_NAME}"
8
8
  s.summary = "Project template manager"
9
9
  # == CONFIGURE ==
10
- s.add_dependency('httparty', '=0.4.5')
11
10
  s.executables << GEM_NAME
12
11
  s.extra_rdoc_files = [ "README.markdown" ]
13
12
  s.files = GEM_FILES.to_a
@@ -15,5 +14,5 @@ GEM_SPEC = Gem::Specification.new do |s|
15
14
  s.name = GEM_NAME
16
15
  s.platform = Gem::Platform::RUBY
17
16
  s.require_path = "lib"
18
- s.version = "0.1.0"
17
+ s.version = "0.1.1"
19
18
  end
data/lib/stencil.rb CHANGED
@@ -5,39 +5,41 @@ end
5
5
  class Stencil
6
6
 
7
7
  def initialize(args)
8
- @path = Dir.pwd
9
- @name = File.basename(@path).intern
8
+ path = Dir.pwd
9
+ name = File.basename(path).intern
10
10
 
11
11
  # If template, do a template merge
12
- if Config.exists?(:templates, @path)
13
- Merge.template(@path)
12
+ if Config.exists?(:templates, path)
13
+ Merge.template(path)
14
14
 
15
15
  # If project
16
- elsif Config.exists?(:projects, @path)
16
+ elsif Config.exists?(:projects, path)
17
17
 
18
18
  # If upstream commit, merge upstream
19
- if args.first('<')
20
- Merge.upstream args[1..-1]
19
+ if args.first == '^'
20
+ Merge.upstream *args[1..-1].unshift(name) and return
21
21
 
22
22
  # If template specified, update config
23
23
  elsif args.first
24
24
  Config.update(:projects => {
25
- @name => {
26
- :template => template,
27
- :branches => branches
25
+ name => {
26
+ :template => args.shift,
27
+ :branches => args
28
28
  }
29
29
  })
30
+
31
+ end
30
32
 
31
33
  # Do a project merge
32
- Merge.project(@path)
34
+ Merge.project(name, path)
33
35
 
34
36
  # If not configured
35
37
  else
36
38
 
37
39
  # Update config
38
- Msg.is_template_or_project?(@name)
40
+ Msg.is_template_or_project?(name)
39
41
  Config.update((STDIN.gets[0..0].downcase == 't' ? :templates : :projects) => {
40
- @name => { :path => @path }
42
+ name => { :path => path }
41
43
  })
42
44
 
43
45
  # Re-run
data/lib/stencil/merge.rb CHANGED
@@ -2,17 +2,15 @@ class Stencil
2
2
  class Merge
3
3
  class <<self
4
4
 
5
- def project(path)
6
- template = Config.read[:projects][@name][:template]
7
- branches = Config.read[:projects][@name][:branches]
5
+ def project(name, path)
6
+ template = Config.read[:projects][name][:template]
7
+ branches = Config.read[:projects][name][:branches]
8
8
  if template
9
9
  template = Config.read[:templates][template.intern]
10
10
  if template && File.exists?(template[:path])
11
- origin = Cmd.run template[:path], "git remote show origin"
12
- origin = origin.match(/URL:\s+(\S+)/)[1]
11
+ origin = get_origin template[:path]
13
12
  Msg.template_url origin
14
- Cmd.run path, "git remote rm template"
15
- Cmd.run path, "git remote add template #{origin}"
13
+ add_remote 'template', path, origin
16
14
  branches = %w(master) if branches.empty?
17
15
  branches.each do |branch|
18
16
  Msg.merge_remote_branch branch
@@ -35,19 +33,53 @@ class Stencil
35
33
  Cmd.run path, "git checkout master"
36
34
  end
37
35
 
36
+ def upstream(name, commit, branches=[])
37
+ project = Config.read[:projects][name]
38
+ branch = Cmd.run(project[:path], "git branch").split
39
+ branch = branch[branch.index('*') + 1]
40
+
41
+ template = Config.read[:templates][project[:template].intern]
42
+ path = template[:path]
43
+
44
+ origin = get_origin project[:path]
45
+ Msg.project_url origin
46
+ add_remote 'project', path, origin
47
+ Cmd.run path, "git fetch project"
48
+
49
+ branches = %w(master) if branches.empty?
50
+ branches.each do |branch|
51
+ output = Cmd.run path, "git checkout #{branch}"
52
+ Msg.error(output) if output.downcase.include?('error')
53
+ Msg.cherry_pick branch, commit
54
+ output = Cmd.run path, "git cherry-pick #{commit}"
55
+ Msg.error(output) if output.downcase.include?('fatal')
56
+ end
57
+ end
58
+
38
59
  private
39
60
 
61
+ def add_remote(name, path, url)
62
+ if Cmd.run(path, "git remote").split.include?(name)
63
+ Cmd.run path, "git remote rm #{name}"
64
+ end
65
+ Cmd.run path, "git remote add #{name} #{url}"
66
+ end
67
+
68
+ def get_origin(path)
69
+ origin = Cmd.run path, "git remote show origin"
70
+ origin.match(/URL:\s+(\S+)/)[1]
71
+ end
72
+
40
73
  def progressive(path, branches)
41
74
  merger = branches.shift
42
75
  mergee = branches.first
43
76
  if merger && mergee
44
77
  puts "Merging \"#{merger}\" into \"#{mergee}\""
45
- output = Cmd.run(path, "git checkout #{mergee} && git merge #{merger}")
46
- if output.downcase.include?('conflict')
47
- puts output
48
- else
49
- progressive(path, branches)
50
- end
78
+ output = Cmd.run path, "git checkout #{mergee}"
79
+ Msg.error(output) if output.downcase.include?('error')
80
+ output = Cmd.run path, "git merge #{merger}"
81
+ Msg.error(output) if output.downcase.include?('conflict')
82
+ progressive(path, branches)
51
83
  end
52
84
  end
53
85
  end
data/lib/stencil/msg.rb CHANGED
@@ -2,24 +2,49 @@ class Stencil
2
2
  class Msg
3
3
  class <<self
4
4
 
5
+ def cherry_pick(branch, commit)
6
+ space
7
+ puts "Cherry picked #{commit} to \"#{branch}\""
8
+ end
9
+
10
+ def error(output)
11
+ space
12
+ puts "Oops:\n#{output}"
13
+ exit
14
+ end
15
+
5
16
  def is_template_or_project?(name)
17
+ space
6
18
  puts "Is \"#{name}\" a template or a project?"
7
19
  end
8
20
 
9
21
  def merge_remote_branch(branch)
22
+ space
10
23
  puts "Merging remote branch \"#{branch}\""
11
24
  end
12
25
 
26
+ def project_url(url)
27
+ space
28
+ puts "Found project URL: #{url}"
29
+ end
30
+
31
+ def space
32
+ puts ''
33
+ end
34
+
13
35
  def specify_template
36
+ space
14
37
  puts "Please tell stencil what template you want to receive updates from:"
15
38
  puts " stencil TEMPLATE [BRANCH BRANCH ...]"
16
39
  end
17
40
 
18
41
  def template_not_found(template)
42
+ space
19
43
  puts "Template \"#{template}\" not found."
20
44
  end
21
45
 
22
46
  def template_url(url)
47
+ space
23
48
  puts "Found template URL: #{url}"
24
49
  end
25
50
  end
data/stencil.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{stencil}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Winton Welsh"]
9
- s.date = %q{2009-11-06}
9
+ s.date = %q{2009-11-09}
10
10
  s.default_executable = %q{stencil}
11
11
  s.email = %q{mail@wintoni.us}
12
12
  s.executables = ["stencil"]
13
13
  s.extra_rdoc_files = ["README.markdown"]
14
- 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"]
14
+ 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"]
15
15
  s.homepage = %q{http://github.com/winton/stencil}
16
16
  s.require_paths = ["lib"]
17
17
  s.rubygems_version = %q{1.3.5}
@@ -22,11 +22,8 @@ Gem::Specification.new do |s|
22
22
  s.specification_version = 3
23
23
 
24
24
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
25
- s.add_runtime_dependency(%q<httparty>, ["= 0.4.5"])
26
25
  else
27
- s.add_dependency(%q<httparty>, ["= 0.4.5"])
28
26
  end
29
27
  else
30
- s.add_dependency(%q<httparty>, ["= 0.4.5"])
31
28
  end
32
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stencil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winton Welsh
@@ -9,19 +9,10 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-06 00:00:00 -08:00
12
+ date: 2009-11-09 00:00:00 -08:00
13
13
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: httparty
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - "="
22
- - !ruby/object:Gem::Version
23
- version: 0.4.5
24
- version:
14
+ dependencies: []
15
+
25
16
  description:
26
17
  email: mail@wintoni.us
27
18
  executables: