@@ -3,19 +3,37 @@ import { exec, exists } from '../node'
33
44const gitOrigin = 'coderoad'
55
6+ const stashAllFiles = async ( ) => {
7+ console . log ( 'stashAllFiles' )
8+ // stash files including untracked (eg. newly created file)
9+ const { stdout, stderr} = await exec ( `git stash --include-untracked` )
10+ if ( stderr ) {
11+ console . error ( stderr )
12+ throw new Error ( 'Error stashing files' )
13+ }
14+ }
15+
616/*
717 SINGLE git cherry-pick %COMMIT%
818 MULTIPLE git cherry-pick %COMMIT_START%..%COMMIT_END%
919 if shell, run shell
20+
21+ if fails, will stash all
1022*/
1123export async function gitLoadCommits ( actions :CR . TutorialAction , dispatch :CR . EditorDispatch ) :Promise < void > {
1224const { commits, commands, files} = actions
1325
1426for ( const commit of commits ) {
27+ // pull a commit from tutorial repo
1528const { stdout, stderr} = await exec ( `git cherry-pick${ commit } ` )
1629if ( stderr ) {
17- console . error ( stderr )
18- throw new Error ( 'Error loading commit' )
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+ }
1937}
2038}
2139
@@ -25,7 +43,6 @@ export async function gitLoadCommits(actions: CR.TutorialAction, dispatch: CR.Ed
2543const { stdout, stderr} = await exec ( command )
2644if ( stderr ) {
2745console . error ( stderr )
28-
2946if ( stderr . match ( / n o d e - g y p / ) ) {
3047// ignored error
3148throw new Error ( 'Error running setup command' )