git_er_done 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/features/cli.feature +27 -1
- data/features/step_definitions/cli_steps.rb +11 -2
- data/lib/git_er_done/app.rb +40 -9
- data/lib/git_er_done/version.rb +1 -1
- metadata +6 -6
data/features/cli.feature
CHANGED
@@ -14,6 +14,19 @@ Feature: CLI
|
|
14
14
|
Then the output should contain "Git-Er-Done"
|
15
15
|
And should display the current version
|
16
16
|
|
17
|
+
Scenario: Complete a Bug
|
18
|
+
Given I am working on a git project
|
19
|
+
And I run `gd bug fix_100`
|
20
|
+
And I commit a new file
|
21
|
+
When I run `gd done`
|
22
|
+
Then the output should contain "Deleted branch bugs/fix_100"
|
23
|
+
Then the output should contain "Switched to branch 'master'"
|
24
|
+
|
25
|
+
Scenario: Start a Bug
|
26
|
+
Given I am working on a git project
|
27
|
+
When I run `gd bug fix_100`
|
28
|
+
Then the output should contain "Switched to a new branch 'bugs/fix_100'"
|
29
|
+
|
17
30
|
Scenario: Start a New Feature
|
18
31
|
Given I am working on a git project
|
19
32
|
When I run `gd feature new_widget`
|
@@ -27,6 +40,19 @@ Feature: CLI
|
|
27
40
|
And the output should contain "Switched to branch 'features/new_widget"
|
28
41
|
And the output should contain "Current branch features/new_widget is up to date"
|
29
42
|
|
43
|
+
Scenario: Shouldn't be able to sync a non-feature branch
|
44
|
+
Given I am working on a git project
|
45
|
+
And I have been working in the "staging" branch
|
46
|
+
When I run `gd sync`
|
47
|
+
Then the script should exit with a warning
|
48
|
+
|
49
|
+
Scenario: Syncing from staging
|
50
|
+
Given I am working on a git project
|
51
|
+
And I have been working in the "staging" branch
|
52
|
+
Then I am working on the "features/new_widget" branch
|
53
|
+
When I run `gd sync`
|
54
|
+
Then the output should not contain "Switched to branch 'master'"
|
55
|
+
|
30
56
|
Scenario: Inception of a branch
|
31
57
|
Given I am working on a git project
|
32
58
|
And I run `git checkout -b staging`
|
@@ -80,4 +106,4 @@ Feature: CLI
|
|
80
106
|
And I commit a new file
|
81
107
|
And I run `gd done` interactively
|
82
108
|
And I type "3"
|
83
|
-
Then the
|
109
|
+
Then the script should fail and exit
|
@@ -46,11 +46,20 @@ When /^I have been working in the "([^"]*)" branch$/ do |branch_name|
|
|
46
46
|
run_simple "git commit -m 'First commit for #{branch_name}'"
|
47
47
|
end
|
48
48
|
|
49
|
-
Then /^the
|
50
|
-
#
|
49
|
+
Then /^the script should fail and exit$/ do
|
50
|
+
# The exit code eally should be 1, but thor doesn't seem to respect error statuses
|
51
51
|
# See http://stackoverflow.com/questions/17241932/ruby-thor-exit-status-in-case-of-an-error
|
52
52
|
steps %Q{
|
53
53
|
Then the exit status should be 0
|
54
54
|
And the output should contain "Error!"
|
55
55
|
}
|
56
|
+
end
|
57
|
+
|
58
|
+
Then /^the script should exit with a warning$/ do
|
59
|
+
# The exit code eally should be 1, but thor doesn't seem to respect error statuses
|
60
|
+
# See http://stackoverflow.com/questions/17241932/ruby-thor-exit-status-in-case-of-an-error
|
61
|
+
steps %Q{
|
62
|
+
Then the exit status should be 0
|
63
|
+
And the output should contain "Warning!"
|
64
|
+
}
|
56
65
|
end
|
data/lib/git_er_done/app.rb
CHANGED
@@ -11,6 +11,7 @@ module Git
|
|
11
11
|
include Git::Er::Done::Actions
|
12
12
|
|
13
13
|
FEATURES_PATH = "features/"
|
14
|
+
BUG_PATH = "bugs/"
|
14
15
|
|
15
16
|
desc 'feature [NAME]', 'Start a new feature using a branch.'
|
16
17
|
def feature(name)
|
@@ -18,6 +19,12 @@ module Git
|
|
18
19
|
git :checkout => "-b #{feature_branch(name)}"
|
19
20
|
end
|
20
21
|
|
22
|
+
desc 'bug [NAME]', 'Start a new bug in a separate branch.'
|
23
|
+
def bug(name)
|
24
|
+
puts "Creating a new bug called #{bug_branch(name)}."
|
25
|
+
git :checkout => "-b #{bug_branch(name)}"
|
26
|
+
end
|
27
|
+
|
21
28
|
desc 'inception', 'Find the branch(es) that the current branch was originally created from.'
|
22
29
|
def inception
|
23
30
|
# Find the first commit that matches one of the heads.
|
@@ -35,16 +42,16 @@ module Git
|
|
35
42
|
Recommend calling sync before doing this.'
|
36
43
|
def done(name=nil)
|
37
44
|
unless name
|
38
|
-
name = current_feature
|
45
|
+
name, type = current_feature
|
39
46
|
end
|
40
|
-
|
47
|
+
say "Completing a #{type} called #{full_branch_name(name, type)}"
|
41
48
|
git :add=>"."
|
42
49
|
git :commit
|
43
50
|
squash
|
44
51
|
# Should we also sync with master first?
|
45
52
|
git :checkout => inception_branch_name
|
46
|
-
git :merge =>
|
47
|
-
git :branch => "-d #{
|
53
|
+
git :merge => full_branch_name(name, type)
|
54
|
+
git :branch => "-d #{full_branch_name(name, type)}"
|
48
55
|
end
|
49
56
|
|
50
57
|
desc 'squash', 'Squash all commits from the current branch into a single commit (since inception).'
|
@@ -64,13 +71,18 @@ module Git
|
|
64
71
|
puts "There are #{commits.size} new commits for #{current_branch_name}"
|
65
72
|
end
|
66
73
|
|
67
|
-
desc 'sync', 'Update your branch with the latest from
|
74
|
+
desc 'sync', 'Update your feature branch with the latest from the inception branch.'
|
68
75
|
def sync
|
76
|
+
if long_running_branch?(current_branch)
|
77
|
+
say "Warning! The current branch ''#{current_branch.name}' is probably a long running branch. It probably has a remote that shouldn't be rebased.' "
|
78
|
+
exit
|
79
|
+
end
|
80
|
+
|
69
81
|
return_to_branch = current_branch_name
|
70
|
-
git :checkout =>
|
82
|
+
git :checkout => inception_branch_name
|
71
83
|
git :pull
|
72
84
|
git :checkout => return_to_branch
|
73
|
-
git :rebase =>
|
85
|
+
git :rebase => inception_branch_name
|
74
86
|
end
|
75
87
|
|
76
88
|
desc 'version', 'Show the Git-Er-Done version and quit. (gd -v works too)'
|
@@ -119,9 +131,12 @@ module Git
|
|
119
131
|
#
|
120
132
|
# @return [Array<Grit::Head>]
|
121
133
|
def long_running_branches
|
122
|
-
repo.heads.select { |head|
|
134
|
+
repo.heads.select { |head| long_running_branch?(head) }
|
123
135
|
end
|
124
136
|
|
137
|
+
def long_running_branch?(branch)
|
138
|
+
!branch.name.include?('features/') && !branch.name.include?('bugs/')
|
139
|
+
end
|
125
140
|
# Returns a list of all commits for the current branch since it was forked from master.
|
126
141
|
def commits_in_feature_branch
|
127
142
|
repo.commits_between(inception_branch_name, current_branch.name)
|
@@ -132,7 +147,9 @@ module Git
|
|
132
147
|
def current_feature
|
133
148
|
b = current_branch_name
|
134
149
|
if b.start_with?(FEATURES_PATH)
|
135
|
-
return b[FEATURES_PATH.length, b.length]
|
150
|
+
return [b[FEATURES_PATH.length, b.length], :feature]
|
151
|
+
elsif b.start_with?(BUG_PATH)
|
152
|
+
return [b[BUG_PATH.length, b.length], :bug]
|
136
153
|
end
|
137
154
|
return ""
|
138
155
|
end
|
@@ -156,9 +173,23 @@ module Git
|
|
156
173
|
raise "No branch named 'master' found."
|
157
174
|
end
|
158
175
|
|
176
|
+
# @param [String] short_branch_name i.e. fix_issue_100
|
177
|
+
# @param [Symbol] type :bug or :feature
|
178
|
+
def full_branch_name(short_branch_name, type)
|
179
|
+
if type == :feature
|
180
|
+
feature_branch(short_branch_name)
|
181
|
+
else
|
182
|
+
bug_branch(short_branch_name)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
159
186
|
def feature_branch(name)
|
160
187
|
"#{FEATURES_PATH}#{name}"
|
161
188
|
end
|
189
|
+
|
190
|
+
def bug_branch(name)
|
191
|
+
"#{BUG_PATH}#{name}"
|
192
|
+
end
|
162
193
|
end
|
163
194
|
end
|
164
195
|
end
|
data/lib/git_er_done/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_er_done
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-05 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
16
|
-
requirement: &
|
16
|
+
requirement: &70103372264780 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.14.6
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70103372264780
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: grit
|
27
|
-
requirement: &
|
27
|
+
requirement: &70103372264320 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '2.4'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70103372264320
|
36
36
|
description: A gem to assist with git workflow, similar to git-flow.
|
37
37
|
email:
|
38
38
|
- peakpg@gmail.com
|