From adb38d0d61e1e5aae04450068586ca025aef0c3f Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 10 Jan 2021 18:28:32 -0500 Subject: [PATCH] checkPlugin: Display a diff of the changes --- bin/plugins/checkPlugin.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/plugins/checkPlugin.js b/bin/plugins/checkPlugin.js index 16a2b0994..43713d4fa 100755 --- a/bin/plugins/checkPlugin.js +++ b/bin/plugins/checkPlugin.js @@ -446,6 +446,14 @@ fs.readdir(pluginPath, (err, rootFiles) => { 'untracked=$(git ls-files -o --exclude-standard) || exit 1; ' + 'git diff-files --quiet && [ -z "$untracked" ] && echo true || echo false')); if (!unchanged) { + // Display a diff of changes. Git doesn't diff untracked files, so they must be added to the + // index. Use a temporary index file to avoid modifying Git's default index file. + execSync('git read-tree HEAD; git add -A && git diff-index -p --cached HEAD && echo ""', { + env: {...process.env, GIT_INDEX_FILE: '.git/checkPlugin.index'}, + stdio: 'inherit', + }); + fs.unlinkSync(`${pluginPath}/.git/checkPlugin.index`); + const cmd = [ 'git add -A', 'git commit -m "autofixes from Etherpad checkPlugin.js"', @@ -455,7 +463,7 @@ fs.readdir(pluginPath, (err, rootFiles) => { console.log('Attempting autocommit and auto publish to npm'); execSync(cmd, {stdio: 'inherit'}); } else { - console.log('Fixes applied, please check git diff then run the following command:'); + console.log('Fixes applied. Check the above git diff then run the following command:'); console.log(`(cd node_modules/${pluginName} && ${cmd})`); } } else {