Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/whiskey_disk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ def if_task_defined(task, cmd)
end

def safe_branch_checkout(path, my_branch)
%Q(cd #{path} && git checkout -b #{my_branch} origin/#{my_branch} || git checkout #{my_branch} origin/#{my_branch} || git checkout #{my_branch})
%Q(cd #{path} && ) +
%Q((branch=`git symbolic-ref HEAD`; [ $branch == "refs/heads/#{my_branch}" ]) || ) +
%Q(git checkout -b #{my_branch} origin/#{my_branch} || git checkout #{my_branch} origin/#{my_branch} || git checkout #{my_branch})
end

def clone_repository(repo, path, my_branch)
Expand Down
7 changes: 6 additions & 1 deletion spec/whiskey_disk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,12 @@ def system(*args)

it 'does branch checkouts from the repository path' do
@whiskey_disk.checkout_main_repository
@whiskey_disk.buffer.join(' ').should.match(%r{cd /path/to/main/repo && git checkout})
@whiskey_disk.buffer.join(' ').should.match(%r{git checkout})
end

it 'should verify if branch is already checked out' do
@whiskey_disk.checkout_main_repository
@whiskey_disk.buffer.join(' ').should.match(%r{cd /path/to/main/repo && \(branch=\`git symbolic-ref HEAD\`; \[ \$branch == "refs/heads/master" \]\) \|\| git checkout})
end
end

Expand Down