Skip to content

Commit

Permalink
support --branch option in checkoutMainAll, phetsims/tasks#1134
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Oct 10, 2024
1 parent 8bb998f commit 9c5028a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
23 changes: 15 additions & 8 deletions js/grunt/checkoutMainAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,25 @@ const grunt = require( 'grunt' );
* Checks out main for all repositories in the git root directory.
* @public
*/
module.exports = function() {
module.exports = function( branch = 'main' ) {
return new Promise( resolve => {

const command = 'git checkout main';
const command = `git checkout ${branch}`;

const gitRoots = grunt.file.expand( { cwd: '../' }, '*' );
const finished = _.after( gitRoots.length, resolve );
const potentialGitRoots = grunt.file.expand( { cwd: '../' }, '*' );
const finished = _.after( potentialGitRoots.length, resolve );

for ( let i = 0; i < gitRoots.length; i++ ) {
const filename = gitRoots[ i ]; // Don't change to const without rewrapping usages in the closure
if ( filename !== 'babel' && grunt.file.isDir( `../${filename}` ) && grunt.file.exists( `../${filename}/.git` ) ) {
child_process.exec( command, { cwd: `../${filename}` }, error => {
for ( let i = 0; i < potentialGitRoots.length; i++ ) {
const filename = potentialGitRoots[ i ]; // Don't change to const without rewrapping usages in the closure
const repoPath = `../${filename}`;
const cwd = { cwd: repoPath };
if ( filename !== 'babel' && // Always on main
grunt.file.isDir( repoPath ) && // Is a directory
grunt.file.exists( `${repoPath}/.git` ) && // Is a git repo

// Only checkout branch if it exists, don't create a new one.
( branch === 'main' || child_process.execSync( `git branch --list ${branch}`, cwd ).toString().length > 0 ) ) {
child_process.exec( command, cwd, error => {
if ( error ) {
grunt.log.writeln( `error in ${command} for repo ${filename}` );
}
Expand Down
3 changes: 2 additions & 1 deletion js/grunt/tasks/checkout-main-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@


import checkoutMainAll from '../checkoutMainAll';
import getOption from './util/getOption';

( async () => checkoutMainAll() )();
( async () => checkoutMainAll( getOption( 'branch' ) ) )();

0 comments on commit 9c5028a

Please sign in to comment.