Skip to content

Commit 2df6bd7

Browse files
author
Alexandre Salomé
committed
Merge pull request #72 from martin-helmich/feature-implement-getuntrackedfiles
Implement WorkingCopy::getUntrackedFiles.
2 parents 9c5750e + 1d0431d commit 2df6bd7

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Gitonomy/Git/WorkingCopy.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ public function getStatus()
4343

4444
public function getUntrackedFiles()
4545
{
46-
return array();
46+
$lines = explode("\0", $this->run('status', array('--porcelain', '--untracked-files=all', '-z')));
47+
$lines = array_filter($lines, function($l) { return substr($l, 0, 3) === '?? '; });
48+
$lines = array_map(function($l) { return substr($l, 3); }, $lines);
49+
return $lines;
4750
}
4851

4952
public function getDiffPending()

tests/Gitonomy/Git/Tests/WorkingCopyTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,15 @@ public function testDetachedHead()
9999
$this->assertFalse($repository->isHeadAttached(), "HEAD is not attached");
100100
$this->assertTrue($repository->isHeadDetached(), "HEAD is detached");
101101
}
102+
103+
public function testGetUntracked()
104+
{
105+
$repository = self::createFoobarRepository(false);
106+
$wc = $repository->getWorkingCopy();
107+
108+
$file = $repository->getWorkingDir() . '/untracked.txt';
109+
file_put_contents($file, 'foo');
110+
111+
$this->assertContains('untracked.txt', $wc->getUntrackedFiles());
112+
}
102113
}

0 commit comments

Comments
 (0)