def checkout(self, ref, *args, **kwargs):
        result = self._repo.checkout(ref, *args, **kwargs)

        # update ignore cache after a checkout
        self.ignore.update()

        status = self._repo.status()
        for path, status in iteritems(status):
            # path is in current status, move on
            if status == GIT_STATUS_CURRENT:
                continue

            # check if file exists or not
            full_path = self._full_path(path)
            if path not in self._repo.index:
                if path not in self.ignore:
                    try:
                        os.unlink(full_path)
                    except OSError:
                        # path points to a directory containing untracked files
                        rmtree(
                            full_path,
                            onerror=lambda function, fpath, excinfo: log.info(
                                "Repository: Checkout couldn't delete %s", fpath
                            )
                        )
                continue

            # check files stats
            stats = self.get_git_object_default_stats(ref, path)
            current_stat = os.lstat(full_path)

            if stats['st_mode'] != current_stat.st_mode:
                os.chmod(full_path, current_stat.st_mode)
                self._repo.index.add(self._sanitize(path))

        return result
dataset/ETHPy150Open PressLabs/gitfs/gitfs/repository.py/Repository.checkout/original