stencil 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/gemspec.rb CHANGED
@@ -14,5 +14,5 @@ GEM_SPEC = Gem::Specification.new do |s|
14
14
  s.name = GEM_NAME
15
15
  s.platform = Gem::Platform::RUBY
16
16
  s.require_path = "lib"
17
- s.version = "0.1.1"
17
+ s.version = "0.1.2"
18
18
  end
@@ -5,23 +5,26 @@ class Stencil
5
5
  def project(name, path)
6
6
  template = Config.read[:projects][name][:template]
7
7
  branches = Config.read[:projects][name][:branches]
8
- if template
9
- template = Config.read[:templates][template.intern]
10
- if template && File.exists?(template[:path])
11
- origin = get_origin template[:path]
12
- Msg.template_url origin
13
- add_remote 'template', path, origin
14
- branches = %w(master) if branches.empty?
15
- branches.each do |branch|
16
- Msg.merge_remote_branch branch
17
- Cmd.run path, "git pull template #{branch}"
18
- end
19
- else
20
- Msg.template_not_found template
21
- Msg.specify_template
8
+ Msg.error_specify_template unless template
9
+ template = Config.read[:templates][template.intern]
10
+ if template && File.exists?(template[:path])
11
+
12
+ # Add remote template to project
13
+ origin = get_origin template[:path]
14
+ Msg.template_url origin
15
+ add_remote 'template', path, origin
16
+
17
+ # Pull template into master if no branches specified
18
+ branches = %w(master) if branches.empty?
19
+
20
+ # Pull template into each branch
21
+ branches.each do |branch|
22
+ Msg.merge_remote_branch branch
23
+ Cmd.run path, "git pull template #{branch}"
22
24
  end
23
25
  else
24
- Msg.specify_template
26
+ Msg.template_not_found template
27
+ Msg.error_specify_template
25
28
  end
26
29
  end
27
30
 
@@ -33,20 +36,32 @@ class Stencil
33
36
  Cmd.run path, "git checkout master"
34
37
  end
35
38
 
36
- def upstream(name, commit, branches=[])
39
+ def upstream(name, commit=nil, branches=[])
40
+ # Project variables
37
41
  project = Config.read[:projects][name]
38
42
  branch = Cmd.run(project[:path], "git branch").split
39
43
  branch = branch[branch.index('*') + 1]
40
44
 
45
+ # Template variables
41
46
  template = Config.read[:templates][project[:template].intern]
42
47
  path = template[:path]
43
48
 
49
+ # Add remote project to template and fetch
44
50
  origin = get_origin project[:path]
45
51
  Msg.project_url origin
46
52
  add_remote 'project', path, origin
47
53
  Cmd.run path, "git fetch project"
48
54
 
55
+ # Get last commit if none specified
56
+ unless commit
57
+ cmd = "git log HEAD~1..HEAD --pretty=format:'%H'"
58
+ commit = Cmd.run(template[:path], cmd).strip
59
+ end
60
+
61
+ # Cherry pick into master if no branches specified
49
62
  branches = %w(master) if branches.empty?
63
+
64
+ # Cherry pick commit into branches
50
65
  branches.each do |branch|
51
66
  output = Cmd.run path, "git checkout #{branch}"
52
67
  Msg.error(output) if output.downcase.include?('error')
@@ -74,7 +89,7 @@ class Stencil
74
89
  merger = branches.shift
75
90
  mergee = branches.first
76
91
  if merger && mergee
77
- puts "Merging \"#{merger}\" into \"#{mergee}\""
92
+ Msg.merging_x_into_y merger, mergee
78
93
  output = Cmd.run path, "git checkout #{mergee}"
79
94
  Msg.error(output) if output.downcase.include?('error')
80
95
  output = Cmd.run path, "git merge #{merger}"
@@ -13,6 +13,13 @@ class Stencil
13
13
  exit
14
14
  end
15
15
 
16
+ def error_specify_template
17
+ space
18
+ puts "Please tell stencil what template you want to receive updates from:"
19
+ puts " stencil TEMPLATE [BRANCH BRANCH ...]"
20
+ exit
21
+ end
22
+
16
23
  def is_template_or_project?(name)
17
24
  space
18
25
  puts "Is \"#{name}\" a template or a project?"
@@ -23,6 +30,10 @@ class Stencil
23
30
  puts "Merging remote branch \"#{branch}\""
24
31
  end
25
32
 
33
+ def merging_x_into_y(x, y)
34
+ puts "Merging \"#{x}\" into \"#{y}\""
35
+ end
36
+
26
37
  def project_url(url)
27
38
  space
28
39
  puts "Found project URL: #{url}"
@@ -32,12 +43,6 @@ class Stencil
32
43
  puts ''
33
44
  end
34
45
 
35
- def specify_template
36
- space
37
- puts "Please tell stencil what template you want to receive updates from:"
38
- puts " stencil TEMPLATE [BRANCH BRANCH ...]"
39
- end
40
-
41
46
  def template_not_found(template)
42
47
  space
43
48
  puts "Template \"#{template}\" not found."
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{stencil}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
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"]
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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winton Welsh