@@ -13,28 +13,41 @@ const stashAllFiles = async () => {
1313}
1414}
1515
16+ const cherryPickCommit = async ( commit :string , count = 0 ) :Promise < void > => {
17+ if ( count > 1 ) {
18+ console . warn ( 'cherry-pick failed' )
19+ return
20+ }
21+ try {
22+ const { stdout} = await exec ( `git cherry-pick${ commit } ` )
23+ if ( ! stdout ) {
24+ throw new Error ( 'No cherry-pick output' )
25+ }
26+ } catch ( error ) {
27+ console . log ( 'cherry-pick-commit failed' )
28+ // stash all files if cherry-pick fails
29+ await stashAllFiles ( )
30+ return cherryPickCommit ( commit , ++ count )
31+ }
32+ }
33+
34+ const errorMessages = {
35+ js :{
36+ 'node-gyp' :'Error running npm setup command'
37+ }
38+ }
39+
1640/*
1741 SINGLE git cherry-pick %COMMIT%
18- MULTIPLE git cherry-pick %COMMIT_START%..%COMMIT_END%
19- if shell, run shell
20-
21- if fails, will stash all
42+ if fails, will stash all and retry
2243*/
2344export async function gitLoadCommits ( actions :CR . TutorialAction , dispatch :CR . EditorDispatch ) :Promise < void > {
2445const { commits, commands, files} = actions
2546
2647for ( const commit of commits ) {
2748// pull a commit from tutorial repo
28- const { stdout, stderr} = await exec ( `git cherry-pick${ commit } ` )
29- if ( stderr ) {
30- console . warn ( 'cherry-pick failed' )
31- // likely merge conflict with cherry-pick
32- await stashAllFiles ( )
33- const { stderr :secondFailure } = await exec ( `git cherry-pick${ commit } ` )
34- if ( secondFailure ) {
35- throw new Error ( 'Error loading commit' )
36- }
37- }
49+ console . log ( `try cherry-pick${ commit } ` )
50+ await cherryPickCommit ( commit )
3851}
3952
4053if ( commands ) {
@@ -43,9 +56,12 @@ export async function gitLoadCommits(actions: CR.TutorialAction, dispatch: CR.Ed
4356const { stdout, stderr} = await exec ( command )
4457if ( stderr ) {
4558console . error ( stderr )
46- if ( stderr . match ( / n o d e - g y p / ) ) {
47- // ignored error
48- throw new Error ( 'Error running setup command' )
59+ // langauge specific error messages from running commands
60+ for ( const message of Object . keys ( errorMessages . js ) ) {
61+ if ( stderr . match ( message ) ) {
62+ // ignored error
63+ throw new Error ( 'Error running setup command' )
64+ }
4965}
5066}
5167console . log ( `run command:${ command } ` , stdout )