protected function getWorktreeDirectory()
    {
        if ($this->worktreeDirectory === null) {
            $config = $this->app->make('community_translation/config');
            $dir = $config->get('options.tempDir');
            $dir = is_string($dir) ? rtrim(str_replace(DIRECTORY_SEPARATOR, '/', $dir), '/') : '';
            if ($dir === '') {
                $fh = $this->app->make('helper/file');
                $dir = $fh->getTemporaryDirectory();
                $dir = is_string($dir) ? rtrim(str_replace(DIRECTORY_SEPARATOR, '/', $dir), '/') : '';
                if ($dir === '') {
                    throw new UserMessageException(t('Unable to retrieve the temporary directory.'));
                }
            }
            $fs = $this->getFilesystem();
            $dir = $dir . '/git-repositories';
            if (!@$fs->isDirectory($dir)) {
                @$fs->makeDirectory($dir, DIRECTORY_PERMISSIONS_MODE_COMPUTED, true);
                if (!@$fs->isDirectory($dir)) {
                    throw new UserMessageException(t('Unable to create a temporary directory.'));
                }
            }
            $file = $dir . '/index.html';
            if (!$fs->isFile($file)) {
                if (@$fs->put($file, '') === false) {
                    throw new UserMessageException(t('Error initializing a temporary directory.'));
                }
            }
            $file = $dir . '/.htaccess';
            if (!$fs->isFile($file)) {
                if (@$fs->put($file, <<<'EOT'
Order deny,allow
Deny from all
php_flag engine off
EOT
                    ) === false) {
                    throw new UserMessageException(t('Error initializing a temporary directory.'));
                }
            }
            $handle = strtolower($this->gitRepository->getURL());
            $handle = preg_replace('/[^a-z0-9\-_\.]+/', '_', $handle);
            $handle = preg_replace('/_+/', '_', $handle);
            $dir .= '/' . $handle;
            $this->worktreeDirectory = $dir;
        }

        return $this->worktreeDirectory;
    }