Skip to content

Commit 0b21056

Browse files
Switch from log to diff for $BRANCH_FILES
To not include files that where added and removed during branch development, the switch to diff-tree was made. Fixes issue #274
1 parent 7b0feb0 commit 0b21056

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

src/Runner/Action/Cli/Command/Placeholder/BranchFiles.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function replacement(array $options): string
4646
$this->io->write('could not find branch start');
4747
return '';
4848
}
49-
$files = $this->repository->getLogOperator()->getChangedFilesSince($start, ['A', 'C', 'M', 'R']);
49+
$files = $this->repository->getDiffOperator()->getChangedFiles($start, $branch, ['A', 'C', 'M', 'R']);
5050

5151
return implode(($options['separated-by'] ?? ' '), FileList::filter($files, $options));
5252
}

tests/unit/Runner/Action/Cli/Command/Placeholder/BranchFilesTest.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ public function testFindStarByReflogWithCustomSeparator(): void
4040
$repo = $this->createRepositoryMock();
4141
$info = $this->createGitInfoOperator();
4242
$log = $this->createGitLogOperator();
43+
$diff = $this->createGitDiffOperator(['file1.php', 'file2.php', 'README.md']);
4344

44-
$log->expects($this->once())
45-
->method('getChangedFilesSince')
46-
->willReturn(['file1.php', 'file2.php', 'README.md']);
4745
$log->expects($this->once())
4846
->method('getBranchRevFromRefLog')
4947
->willReturn('main');
@@ -52,6 +50,7 @@ public function testFindStarByReflogWithCustomSeparator(): void
5250
->willReturn('foo');
5351

5452
$repo->expects($this->atLeastOnce())->method('getLogOperator')->willReturn($log);
53+
$repo->expects($this->atLeastOnce())->method('getDiffOperator')->willReturn($diff);
5554
$repo->expects($this->atLeastOnce())->method('getInfoOperator')->willReturn($info);
5655

5756
$placeholder = new BranchFiles($io, $config, $repo);
@@ -96,16 +95,13 @@ public function testCompareToOfType(): void
9695
$config = $this->createConfigMock();
9796
$repo = $this->createRepositoryMock();
9897
$info = $this->createGitInfoOperator();
99-
$log = $this->createGitLogOperator();
98+
$diff = $this->createGitDiffOperator(['file1.php', 'file2.php', 'README.md', 'foo.txt']);
10099

101-
$log->expects($this->once())
102-
->method('getChangedFilesSince')
103-
->willReturn(['file1.php', 'file2.php', 'README.md', 'foo.txt']);
104100
$info->expects($this->once())
105101
->method('getCurrentBranch')
106102
->willReturn('foo');
107103

108-
$repo->expects($this->atLeastOnce())->method('getLogOperator')->willReturn($log);
104+
$repo->expects($this->atLeastOnce())->method('getDiffOperator')->willReturn($diff);
109105
$repo->expects($this->atLeastOnce())->method('getInfoOperator')->willReturn($info);
110106

111107
$placeholder = new BranchFiles($io, $config, $repo);
@@ -123,16 +119,13 @@ public function testFilterByDirectory(): void
123119
$config = $this->createConfigMock();
124120
$repo = $this->createRepositoryMock();
125121
$info = $this->createGitInfoOperator();
126-
$log = $this->createGitLogOperator();
122+
$diff = $this->createGitDiffOperator(['foo/file1.php', 'foo/file2.php', 'README.md', 'foo.txt']);
127123

128-
$log->expects($this->once())
129-
->method('getChangedFilesSince')
130-
->willReturn(['foo/file1.php', 'foo/file2.php', 'README.md']);
131124
$info->expects($this->once())
132125
->method('getCurrentBranch')
133126
->willReturn('foo');
134127

135-
$repo->expects($this->atLeastOnce())->method('getLogOperator')->willReturn($log);
128+
$repo->expects($this->atLeastOnce())->method('getDiffOperator')->willReturn($diff);
136129
$repo->expects($this->atLeastOnce())->method('getInfoOperator')->willReturn($info);
137130

138131
$placeholder = new BranchFiles($io, $config, $repo);
@@ -150,16 +143,13 @@ public function testReplaceWith(): void
150143
$config = $this->createConfigMock();
151144
$repo = $this->createRepositoryMock();
152145
$info = $this->createGitInfoOperator();
153-
$log = $this->createGitLogOperator();
146+
$diff = $this->createGitDiffOperator(['foo/file1.php', 'foo/file2.php', 'README.md']);
154147

155-
$log->expects($this->once())
156-
->method('getChangedFilesSince')
157-
->willReturn(['foo/file1.php', 'foo/file2.php', 'README.md']);
158148
$info->expects($this->once())
159149
->method('getCurrentBranch')
160150
->willReturn('foo');
161151

162-
$repo->expects($this->atLeastOnce())->method('getLogOperator')->willReturn($log);
152+
$repo->expects($this->atLeastOnce())->method('getDiffOperator')->willReturn($diff);
163153
$repo->expects($this->atLeastOnce())->method('getInfoOperator')->willReturn($info);
164154

165155
$placeholder = new BranchFiles($io, $config, $repo);

0 commit comments

Comments
 (0)