Skip to content

Commit 1997afc

Browse files
committed
stash files if cherry-pick conflict
1 parent 01c7c98 commit 1997afc

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/services/git/index.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,37 @@ import { exec, exists } from '../node'
33

44
const 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
*/
1123
export async function gitLoadCommits(actions: CR.TutorialAction, dispatch: CR.EditorDispatch): Promise<void> {
1224
const { commits, commands, files } = actions
1325

1426
for (const commit of commits) {
27+
// pull a commit from tutorial repo
1528
const { stdout, stderr } = await exec(`git cherry-pick ${commit}`)
1629
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+
}
1937
}
2038
}
2139

@@ -25,7 +43,6 @@ export async function gitLoadCommits(actions: CR.TutorialAction, dispatch: CR.Ed
2543
const { stdout, stderr } = await exec(command)
2644
if (stderr) {
2745
console.error(stderr)
28-
2946
if (stderr.match(/node-gyp/)) {
3047
// ignored error
3148
throw new Error('Error running setup command')

0 commit comments

Comments
 (0)