ding 0.6.0 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -3
- data/lib/ding/cli.rb +53 -17
- data/lib/ding/models/git.rb +16 -2
- data/lib/ding/version.rb +1 -1
- data/lib/ding.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1448685cc5d407fbdd9924ac31a25a64d2faf4ac
|
4
|
+
data.tar.gz: de0955b503538011870dcfaf5e7b95318428c079
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9c454b3caf74446e05117033986edf0576af89e7c82bfe7ecd19113bd6014e64b8ba450e42af92b1b5ea0969e250d6dd6bdaade9d0521f48616213396e857c6
|
7
|
+
data.tar.gz: 3474202fb0762eaa9fb0264635f923c265d6d002c4622bab12c05a61e3121912e8bc4064c27db9bcec4b8f846a23e79773a01a79aaf912da697c0456dd523280
|
data/README.md
CHANGED
@@ -15,12 +15,13 @@ The usual method works:
|
|
15
15
|
|
16
16
|
By default, `ding` will create a branch called `testing` from the
|
17
17
|
selected feature branch. It also assumes that the master branch is
|
18
|
-
called `master
|
19
|
-
|
18
|
+
called `master` and the main development branch is called `develop`.
|
19
|
+
These main branches cannot be deleted using `Ding::Git.delete_branch`.
|
20
20
|
|
21
21
|
These defaults can be over-ridden by providing ENV vars to the shell:
|
22
22
|
|
23
23
|
DING_MASTER_BRANCH - main branch to switch to for synchronising
|
24
|
+
DING_DEVELOP_BRANCH - used to compare merge against feature
|
24
25
|
DING_TESTING_BRANCH - branch to over-ride from feature branch
|
25
26
|
DING_SACROSANCT_BRANCHES - space separated list of protected branches
|
26
27
|
|
@@ -43,7 +44,9 @@ There are several commands available with global options for verbosity and forci
|
|
43
44
|
This is the default action so running `ding` is the equivalent of `ding test`.
|
44
45
|
|
45
46
|
There is an option to specify the feature branch pattern to display for
|
46
|
-
selection of the code to be pushed to `testing`.
|
47
|
+
selection of the code to be pushed to `testing`. By default, only
|
48
|
+
remote branches that haven't already been merged to `develop` will be
|
49
|
+
listed, this can be over-ridden by using the `-m` flag.
|
47
50
|
|
48
51
|
$ ding help test
|
49
52
|
|
@@ -51,6 +54,7 @@ selection of the code to be pushed to `testing`.
|
|
51
54
|
ding test
|
52
55
|
|
53
56
|
Options:
|
57
|
+
-m, [--merged], [--no-merged] # display branches that have been merged
|
54
58
|
-p, [--pattern=PATTERN] # specify a pattern for listing branches
|
55
59
|
# Default: origin/XAP*
|
56
60
|
|
data/lib/ding/cli.rb
CHANGED
@@ -8,15 +8,16 @@ module Ding
|
|
8
8
|
|
9
9
|
default_task :test
|
10
10
|
|
11
|
-
desc "test", "Push a feature branch to the testing branch (this is the default action)"
|
12
|
-
option :
|
11
|
+
desc "test", "Push a feature branch(es) to the testing branch (this is the default action)"
|
12
|
+
option :merged, type: 'boolean', aliases: '-m', default: false, desc: 'display branches that have been merged'
|
13
|
+
option :pattern, type: 'string', aliases: '-p', default: 'origin/XAP*', desc: 'specify a pattern for listing branches'
|
13
14
|
def test
|
14
|
-
|
15
|
-
say "\nDing ding ding: let's
|
15
|
+
develop_branch, testing_branch = Ding::DEVELOP_BRANCH.dup, Ding::TESTING_BRANCH.dup
|
16
|
+
say "\nDing ding ding: let's merge one or more feature branches to #{testing_branch}...\n\n", :green
|
16
17
|
|
17
18
|
repo = Ding::Git.new(options).tap do |r|
|
18
19
|
say "> Synchronising with the remote...", :green
|
19
|
-
r.checkout
|
20
|
+
r.checkout develop_branch
|
20
21
|
r.update
|
21
22
|
end
|
22
23
|
|
@@ -26,17 +27,39 @@ module Ding
|
|
26
27
|
exit 1
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
+
feature_branches = ask_which_item(branches, 'Which feature branch should I use?', :multiple)
|
30
31
|
|
31
32
|
repo.tap do |r|
|
32
33
|
say "\n> Deleting #{testing_branch}...", :green
|
33
34
|
r.delete_branch(testing_branch)
|
34
|
-
|
35
|
-
|
35
|
+
|
36
|
+
say "> Checking out #{develop_branch}...", :green
|
37
|
+
r.checkout(develop_branch)
|
38
|
+
|
36
39
|
say "> Creating #{testing_branch}...", :green
|
37
40
|
r.create_branch(testing_branch)
|
38
|
-
|
39
|
-
|
41
|
+
|
42
|
+
say "> Checking out #{testing_branch}...", :green
|
43
|
+
r.checkout(testing_branch)
|
44
|
+
|
45
|
+
say "> Merging in selected feature #{feature_branches.count == 1 ? 'branch' : 'branches'}...", :green
|
46
|
+
merge_errors = false
|
47
|
+
feature_branches.each do |branch|
|
48
|
+
if r.merge_branch(branch)
|
49
|
+
say ">>> #{branch} succeeded", :green
|
50
|
+
else
|
51
|
+
say ">>> #{branch} failed", :red
|
52
|
+
merge_errors = true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
unless merge_errors
|
57
|
+
say "> Pushing #{testing_branch} to the remote...", :green
|
58
|
+
r.push(testing_branch)
|
59
|
+
else
|
60
|
+
say "\n --> There were merge errors, ding dang it!\n\n", :red
|
61
|
+
exit 1
|
62
|
+
end
|
40
63
|
end
|
41
64
|
|
42
65
|
rescue => e
|
@@ -100,14 +123,17 @@ module Ding
|
|
100
123
|
private
|
101
124
|
|
102
125
|
def show_error(e)
|
103
|
-
say "\n -->
|
126
|
+
say "\n --> ERROR: #{e.message}\n\n", :red
|
104
127
|
raise if options[:verbose]
|
105
128
|
exit 1
|
106
129
|
end
|
107
130
|
|
108
|
-
|
109
|
-
|
131
|
+
# presents a list of choices and allows either a single or multiple selection
|
132
|
+
# returns the selected choices in an array or exist if selection is invalid
|
133
|
+
def ask_which_item(items, prompt, mode=:single)
|
134
|
+
return Array(items.first) if items.size == 1
|
110
135
|
str_format = "\n %#{items.count.to_s.size}s: %s"
|
136
|
+
prompt = prompt << "\n > Enter multiple selections separated by ',' or 'A' for all" if mode == :multiple
|
111
137
|
question = set_color prompt, :yellow
|
112
138
|
answers = {}
|
113
139
|
|
@@ -118,10 +144,20 @@ module Ding
|
|
118
144
|
end
|
119
145
|
|
120
146
|
say question
|
121
|
-
reply = ask(">
|
122
|
-
|
123
|
-
|
124
|
-
|
147
|
+
reply = ask(" >", :yellow).to_s
|
148
|
+
begin
|
149
|
+
replies = reply.split(',')
|
150
|
+
if answers[reply]
|
151
|
+
answers.values_at(reply)
|
152
|
+
elsif mode == :multiple && reply == 'A'
|
153
|
+
answers.values
|
154
|
+
elsif mode == :multiple && !replies.empty?
|
155
|
+
selected_items = answers.values_at(*replies)
|
156
|
+
raise "Invalid selection" if selected_items.include?(nil)
|
157
|
+
selected_items
|
158
|
+
end
|
159
|
+
rescue
|
160
|
+
raise if options[:verbose]
|
125
161
|
say "\n --> That's not a valid selection, I'm out of here!\n\n", :red
|
126
162
|
exit 1
|
127
163
|
end
|
data/lib/ding/models/git.rb
CHANGED
@@ -7,7 +7,8 @@ module Ding
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def branches(pattern)
|
10
|
-
|
10
|
+
merged = options[:merged] ? '--merged' : '--no-merged'
|
11
|
+
%x(git branch --remote --list #{remote_version(pattern)} #{merged}).split
|
11
12
|
end
|
12
13
|
|
13
14
|
def branch_exists?(branch)
|
@@ -19,7 +20,11 @@ module Ding
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def create_branch(branch)
|
22
|
-
raise "Unable to create #{branch}" unless run_cmd "git branch --track #{branch}"
|
23
|
+
raise "Unable to create #{branch}" unless run_cmd "git branch --no-track #{branch}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def current_branch
|
27
|
+
%x(git rev-parse --abbrev-ref HEAD)
|
23
28
|
end
|
24
29
|
|
25
30
|
def delete_branch(branch)
|
@@ -36,6 +41,15 @@ module Ding
|
|
36
41
|
end
|
37
42
|
end
|
38
43
|
|
44
|
+
def merge_branch(branch)
|
45
|
+
raise "Can't merge into protected branch #{current_branch}" if Ding::SACROSANCT_BRANCHES.include?(current_branch)
|
46
|
+
success = !!(run_cmd "git merge -m 'Merge branch #{branch} into #{current_branch}' #{branch}")
|
47
|
+
unless success
|
48
|
+
run_cmd 'git merge --abort'
|
49
|
+
end
|
50
|
+
success
|
51
|
+
end
|
52
|
+
|
39
53
|
def push(branch)
|
40
54
|
checkout branch
|
41
55
|
push_cmd = "git push #{remote_name} #{branch}"
|
data/lib/ding/version.rb
CHANGED
data/lib/ding.rb
CHANGED
@@ -5,8 +5,9 @@ require 'ding/models/ssh'
|
|
5
5
|
|
6
6
|
module Ding
|
7
7
|
MASTER_BRANCH = ENV['DING_MASTER_BRANCH'] || 'master'
|
8
|
+
DEVELOP_BRANCH = ENV['DING_DEVELOP_BRANCH'] || 'develop'
|
8
9
|
TESTING_BRANCH = ENV['DING_TESTING_BRANCH'] || 'testing'
|
9
|
-
SACROSANCT_BRANCHES = (ENV['DING_SACROSANCT_BRANCHES'] ||
|
10
|
+
SACROSANCT_BRANCHES = (ENV['DING_SACROSANCT_BRANCHES'] || "#{MASTER_BRANCH} #{DEVELOP_BRANCH}").split
|
10
11
|
|
11
12
|
# because we lurve the command line... ding!
|
12
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ding
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Warren Bain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06
|
11
|
+
date: 2015-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|