gitscape 1.3.9 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/gitscape/base.rb CHANGED
@@ -22,39 +22,46 @@ class Gitscape::Base
22
22
  end
23
23
 
24
24
  def checkout(branch_name)
25
- begin
26
- @repo.revparse(branch_name)
27
- rescue
28
- raise Exception.new "No branch '#{branch_name}' found"
29
- end
30
- puts "Switching to branch '#{branch_name}'..."
31
- @repo.checkout(branch_name)
25
+ puts "--- Switching to branch '#{branch_name}' ---"
26
+ `git checkout -b #{branch_name}`
27
+
28
+ throw "!!! Failed to switch to branch #{branch_name} !!!" if current_branch_name != branch_name
32
29
  end
33
30
 
34
31
  def git_working_copy_is_clean puts_changes=true
32
+
35
33
  # Check if the working copy is clean, if not, exit
34
+
36
35
  changes = `git status -uno --ignore-submodules=all --porcelain`
37
36
  working_copy_clean = changes.length == 0
38
37
  if !working_copy_clean && puts_changes
39
- puts "Your working copy is not clean, either commit, stash, or reset your changes then try again."
38
+ puts "*** Your working copy is not clean, either commit, stash, or reset your changes then try again. ***"
40
39
  puts changes
41
40
  end
42
41
 
43
42
  working_copy_clean
44
43
  end
45
44
 
46
- def live_current_version_number
47
- current_branch = @repo.current_branch
48
- live_branch = @repo.branch "live"
45
+ def live_iteration
46
+ toRet = `git branch -a --merged live`.split("\n").select{|b| /release\/i(\d+)$/.match b}.map{|b| b.scan(/release\/i(\d+)$/).flatten[0].to_i}.sort.last
47
+ toRet
48
+ end
49
49
 
50
- `git checkout #{live_branch.full}` unless current_branch == live_branch
50
+ def current_branch_name
51
+ toRet = `git status --porcelain -b`.scan(/## (.*)/).flatten[0]
52
+ toRet
53
+ end
51
54
 
52
- version_file = File.new("version", "r")
53
- live_current_version_number = version_file.read.delete("i").to_i
55
+ def current_release_branch_number
56
+ unmerged_into_live_branch_names = `git branch -a --no-merged live`.split("\n")
57
+ release_branch_regex = /release\/i(\d+)$/
54
58
 
55
- `git checkout #{current_branch}` unless current_branch == live_branch
59
+ candidates = unmerged_into_live_branch_names.select{ |b| release_branch_regex.match b}.map{|b| b.scan(release_branch_regex).flatten[0].to_i}.sort
60
+ candidates.last
61
+ end
56
62
 
57
- live_current_version_number
63
+ def current_release_branch_name
64
+ "release/i#{current_release_branch_number}"
58
65
  end
59
66
 
60
67
  def git_has_conflicts puts_conflicts=true
@@ -66,67 +73,63 @@ class Gitscape::Base
66
73
  has_conflicts
67
74
  end
68
75
 
69
- def hotfix_start(hotfix_branch_name=nil)
76
+ def hotfix_start(hotfix_branch=nil)
70
77
  checkout "live"
71
78
 
72
- if hotfix_branch_name.length == 0
73
- exception_message = "*** Improper Usage ***\nExpected Usage: hotfix_start <hotfix_branch_name>"
79
+ if hotfix_branch.length == 0
80
+ exception_message = "*** Improper Usage ***\nExpected Usage: hotfix_start <hotfix_branch>"
74
81
  raise exception_message
75
82
  end
76
83
 
77
- hotfix_branch_name = "hotfix/#{hotfix_branch_name}"
78
- puts "Creating hotfix branch '#{hotfix_branch_name}'..."
84
+ hotfix_branch = "hotfix/#{hotfix_branch}"
85
+ puts "=== Creating hotfix branch '#{hotfix_branch}' ==="
79
86
 
80
- hotfix_branch = @repo.branch(hotfix_branch_name)
81
- `git checkout -b #{hotfix_branch.full}`
82
- @repo.checkout(hotfix_branch)
87
+ puts `git checkout -b #{hotfix_branch}`
83
88
  end
84
89
 
85
- def hotfix_finish(hotfix_branch_name=nil)
90
+ def hotfix_finish(hotfix_branch=nil)
86
91
  # TODO:
87
92
  # 1. Tag the new live revision with 'live/<branch_name_without_prefix>'
88
93
 
89
- usage_string = "expected usage: hotfix_finish [<hotfix_branch_name>]
90
- hotfix_branch_name: the name of the hotfix branch to finish.
94
+ usage_string = "expected usage: hotfix_finish [<hotfix_branch>]
95
+ hotfix_branch: the name of the hotfix branch to finish.
91
96
  if ommitted, you must currently be on a hotfix branch"
92
97
 
93
- previous_branch = @repo.current_branch
98
+ previous_branch = current_branch_name
94
99
 
95
100
  if previous_branch.start_with? "hotfix"
96
- hotfix_branch_name ||= previous_branch
101
+ hotfix_branch ||= previous_branch
97
102
  end
98
103
 
99
- unless @repo.branches.include? hotfix_branch_name
100
- end
101
-
102
- merge_master = true
103
- master_branch = @repo.branch "master"
104
-
105
- if hotfix_branch_name.to_s.empty?
106
- puts "!!! not currently on a hotfix branch, and no branch name was provided as an argument !!!"
104
+ if hotfix_branch.to_s.empty?
105
+ puts "!!! Not currently on a hotfix branch, and no branch name was provided as an argument !!!"
107
106
  puts usage_string
108
107
  exit 1
109
108
  end
110
109
 
111
- hotfix_branch = @repo.branch hotfix_branch_name
112
- # TODO The next line breaks at iteration 100
113
- development_branch = @repo.branches.select {|branch| branch.full.start_with? "release/"}.sort{|a, b| a.name <=> b.name}.last
114
- development_branch = master_branch if development_branch == nil
115
- live_branch = @repo.branch "live"
116
-
117
110
  # Collect the set of branches we'd like to merge the hotfix into
118
- merge_branches = [development_branch, live_branch]
119
- merge_branches << master_branch if !(merge_branches.include? master_branch) && merge_master
111
+ merge_branches = ["master", current_release_branch_name, "live"]
120
112
 
121
- # Merge the hotfix into branches
113
+ # Merge the hotfix into merge_branches
122
114
  for branch in merge_branches
115
+
116
+ # Calculate merge_options
123
117
  merge_options = @merge_options
124
118
  merge_options += " --log" if branch == "master"
125
119
 
126
- `git checkout #{branch.full}`
127
- `git merge #{merge_options} #{hotfix_branch.full}`
120
+ # Attempt merge
121
+ `git checkout #{branch}`
122
+ `git merge #{merge_options} #{hotfix_branch}`
123
+
124
+ # Bail on failures
128
125
  exit 1 if !$?.success?
129
- raise "Merge on #{branch.full} has failed.\nResolve the conflicts and run the script again." if git_has_conflicts
126
+ raise "Merge on #{branch} has failed.\nResolve the conflicts and run the script again." if git_has_conflicts
127
+
128
+ # If we just merged the live branch, tag this revision
129
+ if branch == "live"
130
+ `git tag live/i#{live_iteration}/#{hotfix_branch}`
131
+ end
132
+
130
133
  end
131
134
 
132
135
  # Checkout previous branch for user convenience
@@ -177,7 +180,7 @@ class Gitscape::Base
177
180
  # Get the right release_branch_name to merge
178
181
  current_version_number = new_version_number - 1
179
182
  if new_version_number == 0
180
- current_version_number = live_current_version_number
183
+ current_version_number = live_iteration
181
184
  new_version_number = current_version_number + 1
182
185
  end
183
186
  release_branch_name = "release/i#{new_version_number}"
@@ -1,3 +1,3 @@
1
1
  module Gitscape
2
- VERSION = '1.3.9'
2
+ VERSION = '1.4.0'
3
3
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 3
8
- - 9
9
- version: 1.3.9
7
+ - 4
8
+ - 0
9
+ version: 1.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jon Botelho
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-03-20 00:00:00 -04:00
18
+ date: 2013-03-28 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency