Repository navigation
Closed
Description
Two problems in Repository::diffStaged() (
Lines 2214 to 2235 in 5beb97d
| public function diffStaged(?string $pathspec = null, string $algorithm = 'myers'): array | |
| { | |
| $headId = $this->refs->resolveHead(); | |
| if ($headId === null) { | |
| return []; | |
| } | |
| $commit = $this->objects->read($headId); | |
| if (!$commit instanceof Commit) { | |
| return []; | |
| } | |
| $index = $this->index(); | |
| $treeDiff = new TreeDiff($this->objects, DiffAlgorithmName::normalize($algorithm)); | |
| // Build a tree from the index | |
| $indexTreeId = $this->buildTreeFromIndex($index); | |
| return $treeDiff->diff($commit->tree, $indexTreeId); | |
| } |
- The
$pathspecargument is accepted and documented ($repo->diffStaged('src/specific-file.php')in docs/operations/diff.md) but never used, so every staged file is returned. - Before the first commit (no HEAD) it returns
[](L2218-L2220). git shows every staged file as a new file in that state (git diff --cached), sopitmaster diff --cachedprints nothing for a fresh repository.
Repro
// repo with a.txt and b.txt committed, then both modified and staged
count($repo->diffStaged('a.txt')); // 2, expected 1pitmaster init && printf 'x\n' > a.txt && pitmaster add a.txt
pitmaster diff --cached # prints nothing; git diff --cached shows a.txt as a new fileExpected
Only entries whose old or new path equals the pathspec are returned, and an unborn HEAD is compared against the empty tree.
Metadata
Metadata
Assignees
Labels
No labels
Activity