Skip to content

Commit e31b7ce

Browse files
committed
Some tweaks - remove commits property from branch modifications
1 parent 31c130c commit e31b7ce

File tree

4 files changed

+12
-31
lines changed

4 files changed

+12
-31
lines changed

README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,19 @@ 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-
2013
#### Filter issues by 'lines touched' in current branch
2114

2215
The logic will consider files added, and modified (unstaged, staged, comitted),
2316
filtering out any issues deemed to not have been touched in the current branch
2417

2518
```
26-
// Make a line filter
27-
$git = new Git('/path/to/some/repo-directory');
28-
$lineFilterFactory = new LineFilterFactory($git);
29-
$lineFilter = $lineFilterFactory->makeLineFilter();
19+
// Get modifications for feature branch
20+
$git = new Git('/home/richard/Development/PlotBox/plotbox-app');
21+
$branchModificationsFactory = new BranchModificationsFactory($git);
22+
$branchModifications = $branchModificationsFactory->getBranchModifications();
23+
$lineFilter = new LineFilter($git, $branchModifications);
3024
31-
// Pass in ci-issues to be filtered (third parameter 'attachment' can be anything you like)
25+
// Pass in ci-issues to be filtered
3226
$issues = [
3327
CodeIssue::make('devops/git/post-merge', 123, 'abc123'),
3428
CodeIssue::make('static/maintenance.html', 456, 'abc456')

src/Git/BranchComparer.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,15 @@ public function getAncestorBranch(Branch $currentBranch)
5656
}
5757

5858
/**
59-
* TODO: We should always check against origin. Need to:
60-
* 1. Know the origin name (default to origin)
61-
* 2. Enforce "git fetch --all" before checking..
62-
* 3. Prepend origin to all checks
63-
*
6459
* @param Branch $currentBranch
6560
* @return Branch
6661
*/
6762
private function getNearestStandardAncestor(Branch $currentBranch)
6863
{
6964
$branchDistances = [];
7065
foreach ($this->getStandardAncestors() as $ancestorBranch) {
71-
// Note: If branch doesn't exist locally, we may be checking against an older ancestor
72-
// (develop/master), but that shouldn't be too bad..
66+
// Note: If branch doesn't exist locally (i.e., sprint or release), we may be checking against
67+
// an older ancestor (develop/master), but that shouldn't be too bad..
7368
if ($this->git->branchExists($ancestorBranch)) {
7469
$ancestorBaseCommit = $this->git->getMergeBase($currentBranch, $ancestorBranch);
7570
$distance = $this->distance($currentBranch, $ancestorBaseCommit);

src/Git/BranchModifications.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,21 @@ class BranchModifications
1010
private $modifiedFiles;
1111
/** @var RelativeFile[] */
1212
private $newFiles;
13-
/** @var Commit[] */
14-
private $commits;
1513
/** @var TouchedLines */
1614
private $unstagedChanges;
1715
/**
1816
* @param TouchedLines $modifiedFiles
1917
* @param RelativeFile[] $newFiles
20-
* @param Commit[] $commits
2118
* @param TouchedLines $unstagedChanges
2219
*/
23-
public function __construct(TouchedLines $modifiedFiles, array $newFiles, array $commits, TouchedLines $unstagedChanges)
20+
public function __construct(TouchedLines $modifiedFiles, array $newFiles, TouchedLines $unstagedChanges)
2421
{
2522
$this->modifiedFiles = $modifiedFiles;
2623
$this->newFiles = [];
2724
foreach ($newFiles as $newFile) {
2825
$this->newFiles[$newFile->getPath()] = $newFile;
2926
}
3027
$this->unstagedChanges = $unstagedChanges;
31-
$this->commits = [];
32-
foreach ($commits as $commit) {
33-
$this->commits[$commit->getHash()] = $commit;
34-
}
3528
}
3629

3730
/**

src/Git/BranchModificationsFactory.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function getBranchModifications()
2626
$currentBranch = $this->git->getCurrentBranch();
2727
$ancestorBranch = $branchComparer->getAncestorBranch($currentBranch);
2828
return $this->getBranchModificationsSpecified(
29-
$this->git->getMergeBase($ancestorBranch, $currentBranch),
29+
$ancestorBranch,
3030
$this->git->getLatestCommit($currentBranch)
3131
);
3232
}
@@ -44,20 +44,19 @@ public function getBranchModificationsSpecified(Pointer $ancestorBranch, Pointer
4444
return $this->branchModificationsCached[$cacheKey];
4545
}
4646

47+
// New files appear to be being picked up here also now. May be possible to
48+
// drop the separate newly added files method below..
4749
$modifiedFiles = $this->git->parseTouchedLines(
4850
new ComparisonDiffCommand(
4951
$current,
5052
$ancestorBranch
5153
)
5254
);
5355
$newFiles = $this->git->getNewlyAddedFiles($mergeBase, $current);
54-
$commitList = $this->git->getCommitsBetween($mergeBase, $current);
5556
$unstagedChanges = $this->git->parseTouchedLines(new UnstagedDiffCommand());
56-
5757
$this->branchModificationsCached[$cacheKey] = new BranchModifications(
5858
$modifiedFiles,
5959
$newFiles,
60-
$commitList,
6160
$unstagedChanges
6261
);
6362

0 commit comments

Comments
 (0)