Skip to content

Commit 4c819f7

Browse files
brandonrobertsalxhub
authored andcommitted
style: add combined task to format from git diff and status commands (angular#24969)
PR Close angular#24969
1 parent ac3252a commit 4c819f7

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

gulpfile.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ function loadTask(fileName, taskName) {
2929

3030
gulp.task('format:enforce', loadTask('format', 'enforce'));
3131
gulp.task('format', loadTask('format', 'format'));
32-
gulp.task('format:changed', loadTask('format', 'format-changed'));
32+
gulp.task('format:changes', loadTask('format', 'format-changes'));
33+
gulp.task('format:diff', loadTask('format', 'format-diff'));
34+
gulp.task('format:changed', ['format:changes', 'format:diff']);
3335
gulp.task('build.sh', loadTask('build', 'all'));
3436
gulp.task('build.sh:no-bundle', loadTask('build', 'no-bundle'));
3537
gulp.task('lint', ['format:enforce', 'validate-commit-messages', 'tslint']);

tools/gulp-tasks/format.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ module.exports = {
103103
},
104104

105105
// Format only the changed source code files with clang-format (see .clang-format)
106-
'format-changed': (gulp) => () => {
106+
'format-changes': (gulp) => () => {
107107
const format = require('gulp-clang-format');
108108
const clangFormat = require('clang-format');
109109
const gulpFilter = require('gulp-filter');
@@ -112,5 +112,23 @@ module.exports = {
112112
.pipe(gulpFilter(srcsToFmt))
113113
.pipe(format.format('file', clangFormat))
114114
.pipe(gulp.dest('.'));
115+
},
116+
117+
// Format only the changed source code files diffed from the provided branch with clang-format
118+
// (see .clang-format)
119+
'format-diff': (gulp) => () => {
120+
const format = require('gulp-clang-format');
121+
const clangFormat = require('clang-format');
122+
const gulpFilter = require('gulp-filter');
123+
const minimist = require('minimist');
124+
const gulpGit = require('gulp-git');
125+
126+
const args = minimist(process.argv.slice(2));
127+
const branch = args.branch || 'master';
128+
129+
return gulpGit.diff(branch, {log: false})
130+
.pipe(gulpFilter(srcsToFmt))
131+
.pipe(format.format('file', clangFormat))
132+
.pipe(gulp.dest('.'));
115133
}
116134
};

0 commit comments

Comments
 (0)