From 4c819f79b2b2b3380de4b862c54f75aef9b99ac6 Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Fri, 7 Sep 2018 11:54:47 -0500 Subject: [PATCH] style: add combined task to format from git diff and status commands (#24969) PR Close #24969 --- gulpfile.js | 4 +++- tools/gulp-tasks/format.js | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 97ff7d846d..e9423a6dcb 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -29,7 +29,9 @@ function loadTask(fileName, taskName) { gulp.task('format:enforce', loadTask('format', 'enforce')); gulp.task('format', loadTask('format', 'format')); -gulp.task('format:changed', loadTask('format', 'format-changed')); +gulp.task('format:changes', loadTask('format', 'format-changes')); +gulp.task('format:diff', loadTask('format', 'format-diff')); +gulp.task('format:changed', ['format:changes', 'format:diff']); gulp.task('build.sh', loadTask('build', 'all')); gulp.task('build.sh:no-bundle', loadTask('build', 'no-bundle')); gulp.task('lint', ['format:enforce', 'validate-commit-messages', 'tslint']); diff --git a/tools/gulp-tasks/format.js b/tools/gulp-tasks/format.js index 9b59a7e39a..0b4642e50e 100644 --- a/tools/gulp-tasks/format.js +++ b/tools/gulp-tasks/format.js @@ -103,7 +103,7 @@ module.exports = { }, // Format only the changed source code files with clang-format (see .clang-format) - 'format-changed': (gulp) => () => { + 'format-changes': (gulp) => () => { const format = require('gulp-clang-format'); const clangFormat = require('clang-format'); const gulpFilter = require('gulp-filter'); @@ -112,5 +112,23 @@ module.exports = { .pipe(gulpFilter(srcsToFmt)) .pipe(format.format('file', clangFormat)) .pipe(gulp.dest('.')); + }, + + // Format only the changed source code files diffed from the provided branch with clang-format + // (see .clang-format) + 'format-diff': (gulp) => () => { + const format = require('gulp-clang-format'); + const clangFormat = require('clang-format'); + const gulpFilter = require('gulp-filter'); + const minimist = require('minimist'); + const gulpGit = require('gulp-git'); + + const args = minimist(process.argv.slice(2)); + const branch = args.branch || 'master'; + + return gulpGit.diff(branch, {log: false}) + .pipe(gulpFilter(srcsToFmt)) + .pipe(format.format('file', clangFormat)) + .pipe(gulp.dest('.')); } };