scripts/cherry-pick-commits.js
async function attemptCherryPicks(tag, list, mode) {
  const results = {
    successful: [],
    conflicted: [],
    skipped: [],
  };

  console.log(`Checking out ${tag}`);
  await simpleGit.checkout([tag]);

  for (const logLine of list) {
    if (shouldSkipCommit(logLine, mode)) {
      results.skipped.push(logLine);
      continue;
    }

    try {
      await simpleGit.raw(['cherry-pick', '-x', logLine.hash]);
      results.successful.push(logLine);
    } catch (e) {
      // Detect conflicted cherry-picks and abort them (e.message contains the command's output)
      if (e.message.includes(CONFLICT_MESSAGE)) {
        results.conflicted.push(logLine);
        await simpleGit.raw(['cherry-pick', '--abort']);
      } else if (e.message.includes('is a merge')) {
        const logCommand = `\`git log --oneline --graph ${logLine.hash}\``;
        console.warn(`Merge commit found! Run ${logCommand} and take note of commits on each parent,`);
        console.warn('then compare to your detached history afterwards to ensure no commits of interest were skipped.');
        results.skipped.push(logLine);
      } else {
        console.error(`${logLine.hash} unexpected failure!`, e);
      }
    }
  }

  return results;
}
async function attemptCherryPicks(tag, list, mode) {
  const results = {
    successful: [],
    conflicted: [],
    skipped: [],
  };

  console.log(`Checking out ${tag}`);
  await simpleGit.checkout([tag]);

  for (const logLine of list) {
    if (shouldSkipCommit(logLine, mode)) {
      results.skipped.push(logLine);
      continue;
    }

    try {
      await simpleGit.raw(['cherry-pick', '-x', logLine.hash]);
      results.successful.push(logLine);
    } catch (e) {
      // Detect conflicted cherry-picks and abort them (e.message contains the command's output)
      if (e.message.includes(CONFLICT_MESSAGE)) {
        results.conflicted.push(logLine);
        await simpleGit.raw(['cherry-pick', '--abort']);
      } else if (e.message.includes('is a merge')) {
        const logCommand = `\`git log --oneline --graph ${logLine.hash}\``;
        console.warn(`Merge commit found! Run ${logCommand} and take note of commits on each parent,`);
        console.warn('then compare to your detached history afterwards to ensure no commits of interest were skipped.');
        results.skipped.push(logLine);
      } else {
        console.error(`${logLine.hash} unexpected failure!`, e);
      }
    }
  }

  return results;
}
async function attemptCherryPicks ( tag , list , mode ) { const results = { successful : [ ] , conflicted : [ ] , skipped : [ ] , } ; console . log ( ` ${ tag } ` ) ; await simpleGit . checkout ( [ tag ] ) ; for ( const logLine of list ) { if ( shouldSkipCommit ( logLine , mode ) ) { results . skipped . push ( logLine ) ; continue ; } try { await simpleGit . raw ( [ 'cherry-pick' , '-x' , logLine . hash ] ) ; results . successful . push ( logLine ) ; } catch ( e ) { // Detect conflicted cherry-picks and abort them (e.message contains the command's output) if ( e . message . includes ( CONFLICT_MESSAGE ) ) { results . conflicted . push ( logLine ) ; await simpleGit . raw ( [ 'cherry-pick' , '--abort' ] ) ; } else if ( e . message . includes ( 'is a merge' ) ) { const logCommand = ` \` ${ logLine . hash } \` ` ; console . warn ( ` ${ logCommand } ` ) ; console . warn ( 'then compare to your detached history afterwards to ensure no commits of interest were skipped.' ) ; results . skipped . push ( logLine ) ; } else { console . error ( ` ${ logLine . hash } ` , e ) ; } } } return results ; }
Checks out the given tag and attempts to cherry-pick each commit in the list against it. If a conflict is encountered, that cherry-pick is aborted and processing moves on to the next commit.
Checks out the given tag and attempts to cherry - pick each commit in the list against it . If a conflict is encountered that cherry - pick is aborted and processing moves on to the next commit .