<commit_before><?php
class Vps_Util_Git
{
    private static $_debug = false;
    private $_path;
    public function __construct($path)
    {
        $this->_path = (string)$path;
        if (!file_exists($path.'/.git')) {
            throw new Vps_Exception("Invalid path '$path', no git wc");
        }
    }

    public static function setDebugOutput($enable = true)
    {
        self::$_debug = $enable;
    }

    public static function web()
    {
        static $i;
        if (!isset($i)) $i = new self('.');
        return $i;
    }

    public static function vps()
    {
        static $i;
        if (!isset($i)) $i = new self(VPS_PATH);
        return $i;
    }

    public static function getAuthorName()
    {
        if (isset($_ENV['GIT_AUTHOR_NAME'])) {
            return $_ENV['GIT_AUTHOR_NAME'];
        }
        return trim(`git config user.name`);
    }

    public static function getAuthorEMail()
    {
        if (isset($_ENV['GIT_AUTHOR_EMAIL'])) {
            return $_ENV['GIT_AUTHOR_EMAIL'];
        }
        return trim(`git config user.email`);
    }

    public static function getCommitterName()
    {
        if (isset($_ENV['GIT_COMMITTER_NAME'])) {
            return $_ENV['GIT_COMMITTER_NAME'];
        }
        return trim(`git config user.name`);
    }

    public static function getCommitterEMail()
    {
        if (isset($_ENV['GIT_COMMITER_EMAIL'])) {
            return $_ENV['GIT_COMMITER_EMAIL'];
        }
        return trim(`git config user.email`);
    }

    public static function getAuthorEnvVars()
    {
        return "GIT_AUTHOR_NAME=".escapeshellarg(Vps_Util_Git::getAuthorName()).
               " GIT_AUTHOR_EMAIL=".escapeshellarg(Vps_Util_Git::getAuthorEMail()).
               " GIT_COMMITTER_NAME=".escapeshellarg(Vps_Util_Git::getCommitterName()).
               " GIT_COMMITTER_EMAIL=".escapeshellarg(Vps_Util_Git::getCommitterEMail());
    }

    public static function getGitVersion()
    {
        $cmd = "git --version";
        $gitVersion = trim(exec($cmd));
        if (!preg_match('#^git version ([0-9\\.]+)$#', $gitVersion, $m)) {
            throw new Vps_Exception("can't detect git version");
        }
        return $m[1];
    }

    public function tag($tag, $args = '', $object = '')
    {
        $cmd = "tag -a -m ".escapeshellarg('tagged').' '.$args.' '.escapeshellcmd($tag);
        if ($object) $cmd .= ' '.escapeshellcmd($object);
        $this->system($cmd);
        $this->system("push origin tag ".escapeshellcmd($tag));
    }

    public function branch($branch, $args = '', $object = '')
    {
        $cmd = "branch $args ".escapeshellcmd($branch).' '.escapeshellcmd($object);
        $this->system($cmd);
        $this->system("push origin ".escapeshellcmd($branch));
    }

    public function revParse($obj)
    {
        $d = getcwd();
        chdir($this->_path);
        $cmd = "git rev-parse ".escapeshellcmd($obj)." 2>/dev/null";
        if (self::$_debug) echo $cmd."\n";
        $ret = exec($cmd, $out, $retVar);
        chdir($d);
        if ($retVar) return false;
        if (!$ret) return false;
        return trim($ret);
    }

    public function checkout($target)
    {
        $this->system("checkout ".escapeshellcmd($target));
    }

    public function checkoutBranch($branch, $target)
    {
        $this->system("checkout -b ".escapeshellcmd($branch).' '.escapeshellcmd($target));
    }

    public function fetch()
    {
        $this->system("fetch origin");
    }

    public function pull()
    {
        $this->system("pull origin");
    }

    public function checkClean($against)
    {
        $d = getcwd();
        chdir($this->_path);
        $cmd = "git diff --quiet --exit-code $against";
        if (self::$_debug) echo $cmd."\n";
        system($cmd, $ret);
        chdir($d);
        if (self::$_debug) echo "return $ret\n";
        if ($ret) {
            throw new Vps_ClientException("You must not have modified files in '$this->_path'");
        }
        //TODO GIT check if pushed
    }

    public function getActiveBranch()
    {
        $d = getcwd();
        $cmd = "git branch | grep '^*'";
        chdir($this->_path);
        if (self::$_debug) echo $cmd."\n";
        $ret = exec($cmd);<commit_msg>noch eine todo entfernt die schon erledigt ist<commit_after><?php
class Vps_Util_Git
{
    private static $_debug = false;
    private $_path;
    public function __construct($path)
    {
        $this->_path = (string)$path;
        if (!file_exists($path.'/.git')) {
            throw new Vps_Exception("Invalid path '$path', no git wc");
        }
    }

    public static function setDebugOutput($enable = true)
    {
        self::$_debug = $enable;
    }

    public static function web()
    {
        static $i;
        if (!isset($i)) $i = new self('.');
        return $i;
    }

    public static function vps()
    {
        static $i;
        if (!isset($i)) $i = new self(VPS_PATH);
        return $i;
    }

    public static function getAuthorName()
    {
        if (isset($_ENV['GIT_AUTHOR_NAME'])) {
            return $_ENV['GIT_AUTHOR_NAME'];
        }
        return trim(`git config user.name`);
    }

    public static function getAuthorEMail()
    {
        if (isset($_ENV['GIT_AUTHOR_EMAIL'])) {
            return $_ENV['GIT_AUTHOR_EMAIL'];
        }
        return trim(`git config user.email`);
    }

    public static function getCommitterName()
    {
        if (isset($_ENV['GIT_COMMITTER_NAME'])) {
            return $_ENV['GIT_COMMITTER_NAME'];
        }
        return trim(`git config user.name`);
    }

    public static function getCommitterEMail()
    {
        if (isset($_ENV['GIT_COMMITER_EMAIL'])) {
            return $_ENV['GIT_COMMITER_EMAIL'];
        }
        return trim(`git config user.<EMAIL>`);
    }

    public static function getAuthorEnvVars()
    {
        return "GIT_AUTHOR_NAME=".escapeshellarg(Vps_Util_Git::getAuthorName()).
               " GIT_AUTHOR_EMAIL=".escapeshellarg(Vps_Util_Git::getAuthorEMail()).
               " GIT_COMMITTER_NAME=".escapeshellarg(Vps_Util_Git::getCommitterName()).
               " GIT_COMMITTER_EMAIL=".escapeshellarg(Vps_Util_Git::getCommitterEMail());
    }

    public static function getGitVersion()
    {
        $cmd = "git --version";
        $gitVersion = trim(exec($cmd));
        if (!preg_match('#^git version ([0-9\\.]+)$#', $gitVersion, $m)) {
            throw new Vps_Exception("can't detect git version");
        }
        return $m[1];
    }

    public function tag($tag, $args = '', $object = '')
    {
        $cmd = "tag -a -m ".escapeshellarg('tagged').' '.$args.' '.escapeshellcmd($tag);
        if ($object) $cmd .= ' '.escapeshellcmd($object);
        $this->system($cmd);
        $this->system("push origin tag ".escapeshellcmd($tag));
    }

    public function branch($branch, $args = '', $object = '')
    {
        $cmd = "branch $args ".escapeshellcmd($branch).' '.escapeshellcmd($object);
        $this->system($cmd);
        $this->system("push origin ".escapeshellcmd($branch));
    }

    public function revParse($obj)
    {
        $d = getcwd();
        chdir($this->_path);
        $cmd = "git rev-parse ".escapeshellcmd($obj)." 2>/dev/null";
        if (self::$_debug) echo $cmd."\n";
        $ret = exec($cmd, $out, $retVar);
        chdir($d);
        if ($retVar) return false;
        if (!$ret) return false;
        return trim($ret);
    }

    public function checkout($target)
    {
        $this->system("checkout ".escapeshellcmd($target));
    }

    public function checkoutBranch($branch, $target)
    {
        $this->system("checkout -b ".escapeshellcmd($branch).' '.escapeshellcmd($target));
    }

    public function fetch()
    {
        $this->system("fetch origin");
    }

    public function pull()
    {
        $this->system("pull origin");
    }

    public function checkClean($against)
    {
        $d = getcwd();
        chdir($this->_path);
        $cmd = "git diff --quiet --exit-code $against";
        if (self::$_debug) echo $cmd."\n";
        system($cmd, $ret);
        chdir($d);
        if (self::$_debug) echo "return $ret\n";
        if ($ret) {
            throw new Vps_ClientException("You must not have modified files in '$this->_path'");
        }
    }

    public function getActiveBranch()
    {
        $d = getcwd();
        $cmd = "git branch | grep '^*'";
        chdir($this->_path);
        if (self::$_debug) echo $cmd."\n";
        $ret = exec($cmd);
{'fraction_non_alphanumeric': 0.16137379440131733, 'fraction_numerical': 0.0009409550693954364, 'mean_word_length': 2.226944971537002, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2590892', 'n_tokens_mistral': 2739, 'n_tokens_neox': 2650, 'n_words': 565}