public function ensureGitRemote($dir, $url)
    {
        if (!file_exists($dir . '/.git')) {
            throw new \InvalidArgumentException('The directory is not a Git repository');
        }
        $this->git->ensureInstalled();
        $currentUrl = $this->git->getConfig(
            sprintf('remote.%s.url', $this->config->get('detection.git_remote_name')),
            $dir
        );
        if (!$currentUrl) {
            $this->git->execute(
                ['remote', 'add', $this->config->get('detection.git_remote_name'), $url],
                $dir,
                true
            );
        } elseif ($currentUrl !== $url) {
            $this->git->execute([
                'remote',
                'set-url',
                $this->config->get('detection.git_remote_name'),
                $url
            ], $dir, true);
        }
    }