thegarage-gitx 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b56a879d33daf6209b8e0a9a921c968d376add4b
4
- data.tar.gz: 95b83e8304ad4cfecadac685d71264b5e7d78527
3
+ metadata.gz: c0eea3b7dfcd17fef52f113c503608c7db7ad81d
4
+ data.tar.gz: 04eadf25b646e3aaff99d96e64c3adf1617b6df7
5
5
  SHA512:
6
- metadata.gz: 7146b3e4f1c47734f923d15a85b155cd874aebea870cd27cad5edea6713f9dbde1e939a3b239e33789fd5f7d4518814ec32949bd8f3d1353d7980f42dac9b350
7
- data.tar.gz: b862ca780f3ccedcaba97349024c5b001c9710d12b865df1a5bbe09a3c920557bda8e4bb0af32da3846812e3b885ff49aa782e2ff42ada5078c629eeb3b46dda
6
+ metadata.gz: bea835e6b0f8984ef7ce84c487a67d82ca47220853b1a25b548e21b04e132451bfd575b887730f50b9cc8e26c23ad57d171f8c5a3e8578f5cda4e9860129f44a
7
+ data.tar.gz: cb1ca449eb9a0923b03f10ee20c83d2fff59001df18ef50c7a6137af194256956884c17db8137931bf3b6c0821465cabc91da9bd470508b841b10c67e8e1a793
@@ -31,6 +31,10 @@ module Thegarage
31
31
  end
32
32
  end
33
33
 
34
+ def checkout_branch(branch_name)
35
+ repo.head = "refs/heads/#{branch_name}"
36
+ end
37
+
34
38
  # lookup the current branch of the repo
35
39
  def current_branch
36
40
  repo.branches.find(&:head?)
@@ -7,6 +7,7 @@ module Thegarage
7
7
  module Cli
8
8
  class StartCommand < BaseCommand
9
9
  EXAMPLE_BRANCH_NAMES = %w( api-fix-invalid-auth desktop-cleanup-avatar-markup share-form-add-edit-link )
10
+ VALID_BRANCH_NAME_REGEX = /^[A-Za-z0-9\-_]+$/
10
11
 
11
12
  desc 'start', 'start a new git branch with latest changes from master'
12
13
  def start(branch_name = nil)
@@ -14,16 +15,21 @@ module Thegarage
14
15
  branch_name = ask("What would you like to name your branch? (ex: #{EXAMPLE_BRANCH_NAMES.sample})")
15
16
  end
16
17
 
17
- run_cmd "git checkout #{Thegarage::Gitx::BASE_BRANCH}"
18
+ checkout_branch Thegarage::Gitx::BASE_BRANCH
18
19
  run_cmd 'git pull'
19
- run_cmd "git checkout -b #{branch_name}"
20
+ repo.create_branch branch_name, 'master'
21
+ checkout_branch branch_name
20
22
  end
21
23
 
22
24
  private
23
25
 
24
26
  def valid_new_branch_name?(branch)
25
- remote_branches = Rugged::Branch.each_name(repo, :remote).to_a.map { |branch| branch.split('/').last }
26
- branch =~ /^[A-Za-z0-9\-_]+$/ && !remote_branches.include?(branch)
27
+ return false if remote_branches.include?(branch)
28
+ branch =~ VALID_BRANCH_NAME_REGEX
29
+ end
30
+
31
+ def remote_branches
32
+ @remote_branches ||= Rugged::Branch.each_name(repo, :remote).to_a.map { |branch| branch.split('/').last }
27
33
  end
28
34
  end
29
35
  end
@@ -1,5 +1,5 @@
1
1
  module Thegarage
2
2
  module Gitx
3
- VERSION = '2.0.3'
3
+ VERSION = '2.0.4'
4
4
  end
5
5
  end
@@ -10,18 +10,15 @@ describe Thegarage::Gitx::Cli::StartCommand do
10
10
  }
11
11
  end
12
12
  let(:cli) { Thegarage::Gitx::Cli::StartCommand.new(args, options, config) }
13
- let(:branch) { double('fake branch', name: 'feature-branch') }
14
-
15
- before do
16
- allow(cli).to receive(:current_branch).and_return(branch)
17
- end
13
+ let(:repo) { cli.send(:repo) }
18
14
 
19
15
  describe '#start' do
20
16
  context 'when user inputs branch that is valid' do
21
17
  before do
22
- expect(cli).to receive(:run_cmd).with('git checkout master').ordered
18
+ expect(cli).to receive(:checkout_branch).with('master').ordered
23
19
  expect(cli).to receive(:run_cmd).with('git pull').ordered
24
- expect(cli).to receive(:run_cmd).with('git checkout -b new-branch').ordered
20
+ expect(repo).to receive(:create_branch).with('new-branch', 'master').ordered
21
+ expect(cli).to receive(:checkout_branch).with('new-branch').ordered
25
22
 
26
23
  cli.start 'new-branch'
27
24
  end
@@ -31,11 +28,12 @@ describe Thegarage::Gitx::Cli::StartCommand do
31
28
  end
32
29
  context 'when user does not input a branch name' do
33
30
  before do
34
- expect(cli).to receive(:ask).and_return('another-new-branch')
31
+ expect(cli).to receive(:ask).and_return('new-branch')
35
32
 
36
- expect(cli).to receive(:run_cmd).with('git checkout master').ordered
33
+ expect(cli).to receive(:checkout_branch).with('master').ordered
37
34
  expect(cli).to receive(:run_cmd).with('git pull').ordered
38
- expect(cli).to receive(:run_cmd).with('git checkout -b another-new-branch').ordered
35
+ expect(repo).to receive(:create_branch).with('new-branch', 'master').ordered
36
+ expect(cli).to receive(:checkout_branch).with('new-branch').ordered
39
37
 
40
38
  cli.start
41
39
  end
@@ -45,11 +43,12 @@ describe Thegarage::Gitx::Cli::StartCommand do
45
43
  end
46
44
  context 'when user inputs an invalid branch name' do
47
45
  before do
48
- expect(cli).to receive(:ask).and_return('another-new-branch')
46
+ expect(cli).to receive(:ask).and_return('new-branch')
49
47
 
50
- expect(cli).to receive(:run_cmd).with('git checkout master').ordered
48
+ expect(cli).to receive(:checkout_branch).with('master').ordered
51
49
  expect(cli).to receive(:run_cmd).with('git pull').ordered
52
- expect(cli).to receive(:run_cmd).with('git checkout -b another-new-branch').ordered
50
+ expect(repo).to receive(:create_branch).with('new-branch', 'master').ordered
51
+ expect(cli).to receive(:checkout_branch).with('new-branch').ordered
53
52
 
54
53
  cli.start 'a bad_branch-name?'
55
54
  end
@@ -57,5 +56,20 @@ describe Thegarage::Gitx::Cli::StartCommand do
57
56
  should meet_expectations
58
57
  end
59
58
  end
59
+ context 'when branch already exists in remote repo' do
60
+ before do
61
+ expect(cli).to receive(:ask).and_return('new-branch')
62
+
63
+ expect(cli).to receive(:checkout_branch).with('master').ordered
64
+ expect(cli).to receive(:run_cmd).with('git pull').ordered
65
+ expect(repo).to receive(:create_branch).with('new-branch', 'master').ordered
66
+ expect(cli).to receive(:checkout_branch).with('new-branch').ordered
67
+
68
+ cli.start 'master'
69
+ end
70
+ it 'prompts user to enter a new branch name' do
71
+ should meet_expectations
72
+ end
73
+ end
60
74
  end
61
75
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thegarage-gitx
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Sonnek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-14 00:00:00.000000000 Z
11
+ date: 2014-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged