# File lib/perforce.rb, line 205
  def chdir(dir)
    previous_dir = File.expand_path(".")

    Dir.chdir(dir)
    begin
      @p4.cwd = File.expand_path(".")
    rescue
      Dir.chdir(previous_dir)
      raise
    end

    if block_given?
      begin
        yield dir
      ensure
        Dir.chdir(previous_dir)
        @p4.cwd = previous_dir
      end
    end
  end