git::id_for_pathspec PHP Méthode

id_for_pathspec() static public méthode

Retrieve ids for $pathspec (string or array of strings) at the current branch head
static public id_for_pathspec ( $pathspec )
    static function id_for_pathspec($pathspec)
    {
        if (is_string($pathspec)) {
            return trim(git::exec('rev-parse ' . escapeshellarg(':' . $pathspec)));
        }
        if (!is_array($pathspec)) {
            throw new InvalidArgumentException('$pathspec is ' . gettype($pathspec));
        }
        # array
        $pathspec_to_id = array();
        foreach ($pathspec as $k => $s) {
            $pathspec[$k] = escapeshellarg(':' . $s);
        }
        $lines = explode("\n", trim(git::exec('rev-parse ' . implode(' ', $pathspec))));
        $i = 0;
        foreach ($pathspec as $s) {
            $pathspec_to_id[$s] = $lines[$i++];
        }
        return $pathspec_to_id;
    }

Usage Example

Exemple #1
0
 function isTracked()
 {
     # if it has a real ID, it's tracked
     if (!$this->isWorkVersion()) {
         return true;
     }
     # ask git
     try {
         if ($this->name && git::id_for_pathspec($this->name)) {
             return true;
         }
     } catch (GitError $e) {
     }
     return false;
 }