Skip to content

Commit

Permalink
Merge pull request #668 from seanmil/fix_force_flag
Browse files Browse the repository at this point in the history
Fix force=false behavior on shellgit checkout
  • Loading branch information
scotje authored Dec 12, 2016
2 parents 0cf74b6 + ef99332 commit 49b8b06
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/r10k/git/shellgit/working_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ def clone(remote, opts = {})
# @param ref [String] The git reference to check out
# @param opts [Hash] Optional hash of additional options.
def checkout(ref, opts = {})
argv = ['checkout', ref]

# :force defaults to true
if !opts.has_key?(:force) || opts[:force]
force_opt = '--force'
else
force_opt = ''
argv << '--force'
end

git ['checkout', ref, force_opt], :path => @path.to_s
git argv, :path => @path.to_s
end

def fetch(remote_name='origin')
Expand Down
21 changes: 21 additions & 0 deletions spec/shared-examples/git/working_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,25 @@
expect(subject.origin).to eq remote
end
end

describe "checking out ref" do
before(:each) do
subject.clone(remote)
File.open(File.join(subject.path, 'README.markdown'), 'a') { |f| f.write('local modifications!') }
end

context "with force = true" do
it "should revert changes in managed files" do
subject.checkout(subject.head, {:force => true})
expect(File.read(File.join(subject.path, 'README.markdown')).include?('local modifications!')).to eq false
end
end

context "with force = false" do
it "should not revert changes in managed files" do
subject.checkout(subject.head, {:force => false})
expect(File.read(File.join(subject.path, 'README.markdown')).include?('local modifications!')).to eq true
end
end
end
end

0 comments on commit 49b8b06

Please sign in to comment.