def test_git_dir_outside_work_tree
    Dir.mktmpdir do |work_tree|
      Dir.mktmpdir do |git_dir|
        # Setup a bare repository
        #
        source_git_dir = File.expand_path(File.join('tests', 'files', 'working.git'))
        FileUtils.cp_r(Dir["#{source_git_dir}/*"], git_dir, preserve: true)
        git = Git.open(work_tree, repository: git_dir)

        assert_equal(work_tree, git.dir.path)
        assert_equal(git_dir, git.repo.path)

        # Reconstitute the work tree from the bare repository
        #
        branch = 'master'
        git.checkout(branch, force: true)

        # Make sure the work tree contains the expected files
        #
        expected_files = %w[ex_dir example.txt].sort
        actual_files = Dir[File.join(work_tree, '*')].map { |f| File.basename(f) }.sort
        assert_equal(expected_files, actual_files)

        # None of the expected files should have a status that says it has been changed
        #
        expected_files.each do |file|
          assert_equal(false, git.status.changed?(file))
        end

        # Change a file and make sure it's status says it has been changed
        #
        file = 'example.txt'
        File.open(File.join(work_tree, file), "a") { |f| f.write("A new line") }
        assert_equal(true, git.status.changed?(file))

        # Add and commit the file and then check that:
        # * the file is not flagged as changed anymore
        # * the commit was added to the log
        #
        max_log_size = 100
        assert_equal(64, git.log(max_log_size).size)
        git.add(file)
        git.commit('This is a new commit')
        assert_equal(false, git.status.changed?(file))
        assert_equal(65, git.log(max_log_size).size)
      end
    end
  end
Test the case where the git-dir is not a subdirectory of work-tree