Source

amp / bugs / 23.rb

require 'fileutils'

Amp::Bug.new do |b|
  dir  = "test_#{rand(1000)}"
  repo = nil # scoping
  
  b.number 23
           
  b.desc   "`amp update` fails to replay uncommitted changes"
  
  b.setup do
    repo = Amp::Repositories::Mercurial::LocalRepository.new dir, true # Create the repo
    repo.staging_area.add 'Ampfile'                                    # Add a file
    repo.commit :modified => ['Ampfile'], :message => 'initial commit' # Commit
    
    repo.dirstate.branch = 'new_branch'                                # Create a new branch
    repo.commit :message => 'added a new branch'                       # Save it
    
    repo.switch 'default'                                              # Switch back to default
    File.open("#{dir}/unknown", 'w') {|f| f.write 'unknown' }          # Create an untracked file
  end
  
  b.success do
    repo.switch 'new_branch'                                           # Go back to new_branch
    File.exist? "#{dir}/unknown"                                       # And the file should be there
  end
  
  b.cleanup { FileUtils.rm_rf Dir['test_*'] } # destory all similar looking dirs
end