socialcast-git-extensions 3.2 → 3.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ecdfa89c3f7f393389f3bde1e5d26a9a48776536
4
- data.tar.gz: 4a49a0336e87e091f3dd5301e17a9254fbc2689d
3
+ metadata.gz: 283e0ebc38ce457e94ca898703a5ab8df99835b6
4
+ data.tar.gz: 61d4adc96c8f42e659a03320f2182d844c0aa4ef
5
5
  SHA512:
6
- metadata.gz: 16673110b211af70bbd33b5ec58035976932b576c3f221e22ac2df8b00ee62dcc88f7317fc1ff765cbda6d915dfa9223c5ffb165aadf96604a3ef24ba5ac26be
7
- data.tar.gz: 8e0d1ac0094f6229cc672f65261732d86fa7062c2d43ec465578ae31c87c1e6b90dd8f1fa75476b0c459222d64d5b921fc5ca41439d854655cd64b02d48f7ba3
6
+ metadata.gz: 310fc3393cfae32881d2b4e5ce1ae3fe1645ba9aeff0a2278b60991a89eff7ccd8d4742e4a2191c1ac7424746063ccad0f8828d0dc681f0357796ef31b0ad0a8
7
+ data.tar.gz: 2f8234257b185d9b817be64b9c9c1ca21b790bc2bf867513f66f795f3c6e253fe7141dcd76e3cf34e9b0cdcad381cb45d62df88c8aaf3e37427641edb7b723bd
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.2.2
1
+ ruby-2.2.4
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
3
  - 2.0.0
5
4
  - 2.1.1
5
+ - 2.2.4
data/README.md CHANGED
@@ -46,6 +46,10 @@ integrate the current feature branch into an aggregate branch (ex: prototype, st
46
46
 
47
47
  Find pull requests on github including a given commit
48
48
 
49
+ ## git branchdiff <branch> <base_branch (optional, default: master)>
50
+
51
+ List branches merged into remote origin/`branch` and not also merged into origin/`base_branch`
52
+
49
53
  ## git reviewrequest
50
54
 
51
55
  create a pull request on github for peer review of the current branch.
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'socialcast-git-extensions', 'cli.rb')
4
+ Socialcast::Gitx::CLI.start (['branchdiff'] + ARGV)
@@ -233,6 +233,18 @@ module Socialcast
233
233
  post message.strip
234
234
  end
235
235
 
236
+ desc 'branchdiff', 'show branches merged into one remote branch but not merged into another (default = master)'
237
+ def branchdiff(branch = nil, other_branch = 'master')
238
+ branch ||= ask "What remote branch would you like to compare against '#{other_branch}' (ex: staging)?"
239
+ run_cmd "git fetch origin"
240
+ results = branch_difference(branch, other_branch)
241
+ if results.any?
242
+ say "\nBranches in origin/#{branch} and not in origin/#{other_branch}:\n\n#{results.join("\n")}\n\n"
243
+ else
244
+ say "\nNo branches found in origin/#{branch} that are not also in origin/#{other_branch}\n\n"
245
+ end
246
+ end
247
+
236
248
  desc 'release', 'release the current branch to production'
237
249
  def release
238
250
  branch = current_branch
@@ -74,6 +74,11 @@ module Socialcast
74
74
  branches.uniq
75
75
  end
76
76
 
77
+ # retrieve a list of branches merged into one remote branch but not merged into another
78
+ def branch_difference(branch, other_branch)
79
+ branches(:remote => true, :merged => "origin/#{branch}") - branches(:remote => true, :merged => "origin/#{other_branch}")
80
+ end
81
+
77
82
  # reset the specified branch to the same set of commits as the destination branch
78
83
  # reverts commits on aggregate branches back to a known good state
79
84
  # returns list of branches that were removed
@@ -87,7 +92,7 @@ module Socialcast
87
92
 
88
93
  run_cmd "git checkout #{base_branch}"
89
94
  refresh_branch_from_remote head_branch
90
- removed_branches = branches(:remote => true, :merged => "origin/#{branch}") - branches(:remote => true, :merged => "origin/#{head_branch}")
95
+ removed_branches = branch_difference(branch, head_branch)
91
96
  run_cmd "git branch -D #{branch}" rescue nil
92
97
  run_cmd "git push origin --delete #{branch}" rescue nil
93
98
  run_cmd "git checkout -b #{branch}"
@@ -151,8 +156,8 @@ module Socialcast
151
156
  dir
152
157
  end
153
158
  dir_counts = Hash.new(0)
154
- dirs.each {|dir| dir_counts[dir] += 1 }
155
- changes = dir_counts.to_a.sort_by {|k,v| v}.reverse.first(5).map {|k,v| "#{k} (#{v} file#{'s' if v > 1})"}
159
+ dirs.each { |dir| dir_counts[dir] += 1 }
160
+ changes = dir_counts.to_a.sort_by { |k, v| [-v, k] }.first(5).map { |k, v| "#{k} (#{v} file#{'s' if v > 1})" }
156
161
  else
157
162
  changes = changes.map do |line|
158
163
  added, removed, filename = line.split
@@ -1,5 +1,5 @@
1
1
  module Socialcast
2
2
  module Gitx
3
- VERSION = "3.2"
3
+ VERSION = "3.3"
4
4
  end
5
5
  end
data/spec/cli_spec.rb CHANGED
@@ -365,6 +365,47 @@ describe Socialcast::Gitx::CLI do
365
365
  end
366
366
  end
367
367
 
368
+ describe '#branchdiff' do
369
+ subject(:branchdiff) { Socialcast::Gitx::CLI.start(['branchdiff'] + args) }
370
+ let(:said_messages) { [] }
371
+ before do
372
+ expect_any_instance_of(Socialcast::Gitx::CLI).to receive(:run_cmd).with('git fetch origin')
373
+ allow_any_instance_of(Socialcast::Gitx::CLI).to receive(:say) do |_instance, msg|
374
+ said_messages << msg
375
+ end
376
+ end
377
+ context 'with one branch-name argument' do
378
+ let(:args) { ['my-branch'] }
379
+ before do
380
+ expect_any_instance_of(Socialcast::Gitx::CLI).to receive(:branch_difference).with('my-branch', 'master').and_return(['dummy_branch'])
381
+ branchdiff
382
+ end
383
+ it do
384
+ expect(said_messages).to eq ["\nBranches in origin/my-branch and not in origin/master:\n\ndummy_branch\n\n"]
385
+ end
386
+ end
387
+ context 'with two branch-name arguments' do
388
+ let(:args) { ['my-branch', 'other-branch'] }
389
+ before do
390
+ expect_any_instance_of(Socialcast::Gitx::CLI).to receive(:branch_difference).with('my-branch', 'other-branch').and_return(['dummy_branch'])
391
+ branchdiff
392
+ end
393
+ it do
394
+ expect(said_messages).to eq ["\nBranches in origin/my-branch and not in origin/other-branch:\n\ndummy_branch\n\n"]
395
+ end
396
+ end
397
+ context 'when no results are found' do
398
+ let(:args) { ['my-branch'] }
399
+ before do
400
+ expect_any_instance_of(Socialcast::Gitx::CLI).to receive(:branch_difference).with('my-branch', 'master').and_return([])
401
+ branchdiff
402
+ end
403
+ it do
404
+ expect(said_messages).to eq ["\nNo branches found in origin/my-branch that are not also in origin/master\n\n"]
405
+ end
406
+ end
407
+ end
408
+
368
409
  describe '#nuke' do
369
410
  before { allow_any_instance_of(Socialcast::Gitx::CLI).to receive(:branches).and_return([]) }
370
411
  context 'when target branch == staging and --destination == last_known_good_staging' do
data/spec/git_spec.rb CHANGED
@@ -10,6 +10,20 @@ describe Socialcast::Gitx::Git do
10
10
  let(:test_instance) { TestClass.new }
11
11
  subject { test_instance }
12
12
 
13
+ describe '#branch_difference' do
14
+ subject { test_instance.send(:branch_difference, branch, other_branch) }
15
+ let(:other_branch) { 'master' }
16
+ let(:branch) { 'my-branch' }
17
+ before do
18
+ allow(test_instance).to receive(:branches) do |options|
19
+ expect(options[:remote]).to be_truthy
20
+ next %w(branch_a branch_b branch_c branch_z) if options[:merged] == "origin/#{branch}"
21
+ %w(branch_b branch_d branch_e branch_z) if options[:merged] == "origin/#{other_branch}"
22
+ end
23
+ end
24
+ it { is_expected.to eq %w(branch_a branch_c) }
25
+ end
26
+
13
27
  describe '#changelog_summary' do
14
28
  subject { test_instance.send(:changelog_summary, branch) }
15
29
  let(:base_branch) { 'master' }
@@ -64,13 +78,13 @@ describe Socialcast::Gitx::Git do
64
78
  1 0 doc/images.md
65
79
  EOS
66
80
  end
67
- it 'summarizes the changes by directory' do
81
+ it 'summarizes the changes by directory, sorting by count desc then alpha asc' do
68
82
  is_expected.to eq <<-EOS.strip_heredoc
69
83
  engines/shoelaces/spec/models (2 files)
70
- lib/tasks (1 file)
71
- script (1 file)
72
84
  doc (1 file)
73
85
  engines/shoelaces/app/models (1 file)
86
+ lib/tasks (1 file)
87
+ script (1 file)
74
88
  6 files changed, 35 insertions(+), 129 deletions(-)
75
89
  EOS
76
90
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socialcast-git-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: '3.2'
4
+ version: '3.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Socialcast
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-09 00:00:00.000000000 Z
11
+ date: 2016-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged
@@ -141,6 +141,7 @@ email:
141
141
  - developers@socialcast.com
142
142
  executables:
143
143
  - git-backportpr
144
+ - git-branchdiff
144
145
  - git-cleanup
145
146
  - git-findpr
146
147
  - git-integrate
@@ -166,6 +167,7 @@ files:
166
167
  - README.md
167
168
  - Rakefile
168
169
  - bin/git-backportpr
170
+ - bin/git-branchdiff
169
171
  - bin/git-cleanup
170
172
  - bin/git-findpr
171
173
  - bin/git-integrate