豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 6c6c6b0

Browse files
committed
fix(ng-dev): do not throw if there is no diff between g3 and main
It seems like multimatch previously did not throw when it received an empty file path. We should never need to call multimatch with an empty path, avoiding the runtime error. To fix this, we just do not incorrectly try to derive diff information from an empty line if there is no diff (this was a brittle logic).
1 parent 0268158 commit 6c6c6b0

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

ng-dev/caretaker/check/g3.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,31 @@ describe('G3Module', () => {
7575
expect(files).toBe(2);
7676
expect(commits).toBe(3);
7777
});
78+
79+
it('should not throw when there is no diff between the g3 and main branch', async () => {
80+
getLatestShas.and.returnValue({g3: 'abc123', master: 'zxy987'});
81+
getG3FileIncludeAndExcludeLists.and.returnValue({include: ['project1/*'], exclude: []});
82+
getDiffStats.and.callThrough();
83+
84+
spyOn(GitClient.prototype, 'run').and.callFake((args: string[]): any => {
85+
const output: Partial<SpawnSyncReturns<string>> = {};
86+
if (args[0] === 'rev-list') {
87+
output.stdout = '0';
88+
}
89+
if (args[0] === 'diff') {
90+
output.stdout = '';
91+
}
92+
return output;
93+
});
94+
95+
const module = new G3Module(git, {caretaker: {}, ...mockNgDevConfig});
96+
const {insertions, deletions, files, commits} = (await module.data) as G3StatsData;
97+
98+
expect(insertions).toBe(0);
99+
expect(deletions).toBe(0);
100+
expect(files).toBe(0);
101+
expect(commits).toBe(0);
102+
});
78103
});
79104

80105
describe('printing the data retrieved', () => {

ng-dev/caretaker/check/g3.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,18 @@ export class G3Module extends BaseModule<G3StatsData | void> {
9494
);
9595

9696
// Get the numstat information between main and g3
97-
this.git
97+
const numStatDiff = this.git
9898
.run(['diff', `${g3Ref}...${mainRef}`, '--numstat'])
9999
.stdout // Remove the extra space after git's output.
100-
.trim()
101-
// Split each line of git output into array
100+
.trim();
101+
102+
// If there is no diff, we can return early.
103+
if (numStatDiff === '') {
104+
return stats;
105+
}
106+
107+
// Split each line of git output into array
108+
numStatDiff
102109
.split('\n')
103110
// Split each line from the git output into components parts: insertions,
104111
// deletions and file name respectively
@@ -116,6 +123,7 @@ export class G3Module extends BaseModule<G3StatsData | void> {
116123
stats.files += 1;
117124
}
118125
});
126+
119127
return stats;
120128
}
121129
/** Determine whether the file name passes both include and exclude checks. */

0 commit comments

Comments
 (0)