Skip to content

Commit

Permalink
Merge branch 'fix-start-branch-conflict'
Browse files Browse the repository at this point in the history
* fix-start-branch-conflict:
  Fix git start command to detect when branch already exists locally.
  • Loading branch information
wireframe committed Sep 18, 2014
2 parents 7297991 + 20de794 commit 6e527d6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
8 changes: 5 additions & 3 deletions lib/thegarage/gitx/cli/start_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ def start(branch_name = nil)
private

def valid_new_branch_name?(branch)
return false if remote_branches.include?(branch)
return false if repo_branches.include?(branch)
branch =~ VALID_BRANCH_NAME_REGEX
end

def remote_branches
@remote_branches ||= repo.branches.each_name(:remote).to_a.map { |branch| branch.split('/').last }
def repo_branches
@branch_names ||= repo.branches.each_name.map do |branch|
branch.split('/').last
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/thegarage/gitx/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Thegarage
module Gitx
VERSION = '2.4.0'
VERSION = '2.4.1'
end
end
23 changes: 22 additions & 1 deletion spec/thegarage/gitx/cli/start_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,37 @@
should meet_expectations
end
end
context 'when branch already exists in local repo' do
let(:branches) { double(each_name: ['bar']) }
before do
expect(repo).to receive(:branches).and_return(branches)

expect(cli).to receive(:ask).and_return('new-branch')

expect(cli).to receive(:checkout_branch).with('master').ordered
expect(cli).to receive(:run_cmd).with('git pull').ordered
expect(repo).to receive(:create_branch).with('new-branch', 'master').ordered
expect(cli).to receive(:checkout_branch).with('new-branch').ordered

cli.start 'bar'
end
it 'prompts user to enter a new branch name' do
should meet_expectations
end
end
context 'when branch already exists in remote repo' do
let(:branches) { double(each_name: ['origin/bar']) }
before do
expect(repo).to receive(:branches).and_return(branches)

expect(cli).to receive(:ask).and_return('new-branch')

expect(cli).to receive(:checkout_branch).with('master').ordered
expect(cli).to receive(:run_cmd).with('git pull').ordered
expect(repo).to receive(:create_branch).with('new-branch', 'master').ordered
expect(cli).to receive(:checkout_branch).with('new-branch').ordered

cli.start 'master'
cli.start 'bar'
end
it 'prompts user to enter a new branch name' do
should meet_expectations
Expand Down

0 comments on commit 6e527d6

Please sign in to comment.