public function git_run($command)
    {
        $git = escapeshellarg(pake_which('git'));

        if (self::$needs_work_tree_workaround === true) {
            $cmd = '(cd '.escapeshellarg($this->repository_path).' && '.$git.' '.$command.')';
        } else {
            $cmd = $git;
            $cmd .= ' --git-dir='.escapeshellarg($this->repository_path.'/.git');
            $cmd .= ' --work-tree='.escapeshellarg($this->repository_path);
            $cmd .= ' '.$command;
        }

        try {
            return pake_sh($cmd);
        } catch (pakeException $e) {
            if (strpos($e->getMessage(), 'cannot be used without a working tree') !== false ||
                // workaround for windows (using win7 and git 1.7.10)
                strpos($e->getMessage(), 'fatal: Could not switch to ') !== false) {
                pake_echo_error('Your version of git is buggy. Using workaround');
                self::$needs_work_tree_workaround = true;
                return $this->git_run($command);
            }

            throw $e;
        }
    }