@@ -3,19 +3,37 @@ import { exec, exists } from '../node'
3
3
4
4
const gitOrigin = 'coderoad'
5
5
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
+
6
16
/*
7
17
SINGLE git cherry-pick %COMMIT%
8
18
MULTIPLE git cherry-pick %COMMIT_START%..%COMMIT_END%
9
19
if shell, run shell
20
+
21
+ if fails, will stash all
10
22
*/
11
23
export async function gitLoadCommits ( actions : CR . TutorialAction , dispatch : CR . EditorDispatch ) : Promise < void > {
12
24
const { commits, commands, files } = actions
13
25
14
26
for ( const commit of commits ) {
27
+ // pull a commit from tutorial repo
15
28
const { stdout, stderr } = await exec ( `git cherry-pick ${ commit } ` )
16
29
if ( 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
+ }
19
37
}
20
38
}
21
39
@@ -25,7 +43,6 @@ export async function gitLoadCommits(actions: CR.TutorialAction, dispatch: CR.Ed
25
43
const { stdout, stderr } = await exec ( command )
26
44
if ( stderr ) {
27
45
console . error ( stderr )
28
-
29
46
if ( stderr . match ( / n o d e - g y p / ) ) {
30
47
// ignored error
31
48
throw new Error ( 'Error running setup command' )
0 commit comments