public function setCwd($cwd)
    {
        $this->hasCheckout = false;
        $this->hasClone = false;
        $this->isTemporary = false;

        if (is_null($cwd)) {
            $this->cwd = sys_get_temp_dir() . '/' . uniqid('git');

            // ensure the working directory exists (needed on windows)
            if (!is_dir($this->cwd)) {
                mkdir($this->cwd);
            }

            $this->isTemporary = true;
        } else {
            if (is_dir($cwd)) {
                if (is_dir($cwd . '/.git')) {
                    $this->hasClone = true;
                }
            }
            $this->cwd = $cwd;
        }

        return $this;
    }