3 namespace pharext\SourceDir
;
9 * Extension source directory which is a git repo
11 class Git
implements \IteratorAggregate
, SourceDir
14 * The Packager command
15 * @var pharext\Command
27 * @see \pharext\SourceDir::__construct()
29 public function __construct(Command
$cmd, $path) {
36 * @see \pharext\SourceDir::getBaseDir()
38 public function getBaseDir() {
43 * Generate a list of files by `git ls-files`
46 private function generateFiles() {
49 if (($pipe = popen("git ls-tree -r --name-only HEAD", "r"))) {
50 $path = realpath($this->path
);
51 while (!feof($pipe)) {
52 if (strlen($file = trim(fgets($pipe)))) {
53 if ($this->cmd
->getArgs()->verbose
) {
54 $this->cmd
->info("Packaging %s\n", $file);
56 /* there may be symlinks, so no realpath here */
57 if (!file_exists("$path/$file")) {
58 $this->cmd
->error("File %s does not exist in %s\n", $file, $path);
69 * Implements IteratorAggregate
70 * @see IteratorAggregate::getIterator()
72 public function getIterator() {
73 return $this->generateFiles();