Skip to content

Commit d51de1e

Browse files
committed
Update simple method of getting all 'touched file paths'
1 parent b533f9e commit d51de1e

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ when dealing with legacy code-bases where you want to tackle code smells bit by
1010

1111
### Example Usage
1212

13+
#### Get all 'files touched' in current feature branch
14+
15+
```
16+
$gitService = new GitInfoService();
17+
$touchedFiles = $gitService->filesTouched('/path/to/some/repo');
18+
```
19+
1320
#### Filter issues by 'lines touched' in current branch
1421

1522
The logic will consider files added, and modified (unstaged, staged, comitted),

src/GitInfoService.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace PlotBox\PhpGitOps;
4+
5+
use PlotBox\PhpGitOps\Git\BranchComparer;
6+
use PlotBox\PhpGitOps\Git\BranchModificationsFactory;
7+
use PlotBox\PhpGitOps\Git\Git;
8+
9+
class GitInfoService
10+
{
11+
/**
12+
* Convenience wrapper to find all filepaths that have been touched in
13+
* currently active feature branch
14+
*
15+
* @param $repoDirectory
16+
* @return RelativeFile[]
17+
*/
18+
public function filesTouched($repoDirectory)
19+
{
20+
// Get all files 'touched' in current branch
21+
$git = new Git($repoDirectory);
22+
$branchModificationFactory = new BranchModificationsFactory($git);
23+
$branchComparer = new BranchComparer($git);
24+
$currentBranch = $git->getCurrentBranch();
25+
$ancestorBranch = $branchComparer->getAncestorBranch($currentBranch);
26+
$branchModifications = $branchModificationFactory->getBranchModifications(
27+
$git->getMergeBase($ancestorBranch, $currentBranch),
28+
$git->getLatestCommit($currentBranch)
29+
);
30+
return $branchModifications->getModifiedFilePaths();
31+
}
32+
}

0 commit comments

Comments
 (0)