1/** 2 * Copyright (c) Meta Platforms, Inc. and affiliates. 3 * 4 * This source code is licensed under the MIT license found in the 5 * LICENSE file in the root directory of this source tree. 6 * 7 * @format 8 */ 9 10const {spawnSync} = require('child_process'); 11const path = require('path'); 12 13const ROOT_LOCATION = path.join(__dirname, '..', '..'); 14 15const checkForGitChanges = () => { 16 const {stdout: thereIsSomethingToCommit, stderr} = spawnSync( 17 'git', 18 ['status', '--porcelain'], 19 { 20 cwd: ROOT_LOCATION, 21 shell: true, 22 stdio: 'pipe', 23 encoding: 'utf-8', 24 }, 25 ); 26 27 if (stderr) { 28 console.log( 29 '\u274c An error occured while running `git status --porcelain`:', 30 ); 31 console.log(stderr); 32 33 process.exit(1); 34 } 35 36 return Boolean(thereIsSomethingToCommit); 37}; 38 39module.exports = checkForGitChanges; 40