Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4a1d826

Browse files
committed
validate git installed on startup
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent0bd7607 commit4a1d826

File tree

7 files changed

+71
-23
lines changed

7 files changed

+71
-23
lines changed

‎src/channel/index.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import tutorialConfig from '../actions/tutorialConfig'
88
import{COMMANDS}from'../editor/commands'
99
importloggerfrom'../services/logger'
1010
importContextfrom'./context'
11+
import{versionasgitVersion}from'../services/git'
1112
import{openWorkspace,checkWorkspaceEmpty}from'../services/workspace'
1213

1314
interfaceChannel{
@@ -106,13 +107,21 @@ class Channel implements Channel {
106107
// update the current stepId on startup
107108
vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP,action.payload)
108109
return
109-
case'EDITOR_CHECK_WORKSPACE':
110+
case'EDITOR_VALIDATE_SETUP':
111+
// 1. check workspace is selected
110112
constisEmptyWorkspace=awaitcheckWorkspaceEmpty(this.workspaceRoot.uri.path)
111-
if(isEmptyWorkspace){
112-
this.send({type:'IS_EMPTY_WORKSPACE'})
113-
}else{
113+
if(!isEmptyWorkspace){
114114
this.send({type:'NOT_EMPTY_WORKSPACE'})
115+
return
116+
}
117+
// 2. check Git is installed.
118+
// Should wait for workspace before running otherwise requires access to root folder
119+
constisGitInstalled=awaitgitVersion()
120+
if(!isGitInstalled){
121+
this.send({type:'GIT_NOT_INSTALLED'})
122+
return
115123
}
124+
this.send({type:'SETUP_VALIDATED'})
116125
return
117126
case'EDITOR_REQUEST_WORKSPACE':
118127
console.log('request workspace')

‎src/services/git/index.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export async function clear(): Promise<void> {
6969
thrownewError('Error cleaning up current unsaved work')
7070
}
7171

72-
exportasyncfunctionversion():Promise<string|boolean>{
72+
exportasyncfunctionversion():Promise<string|null>{
7373
const{ stdout, stderr}=awaitnode.exec('git --version')
7474
if(!stderr){
7575
constmatch=stdout.match(/^gitversion(\d+\.)?(\d+\.)?(\*|\d+)/)
@@ -79,10 +79,7 @@ export async function version(): Promise<string | boolean> {
7979
return`${major}${minor}${patch}`
8080
}
8181
}
82-
constmessage='Git not installed. Please install Git'
83-
consterror=newError(message)
84-
onError(error)
85-
throwerror
82+
returnnull
8683
}
8784

8885
asyncfunctioninit():Promise<void>{
@@ -95,12 +92,6 @@ async function init(): Promise<void> {
9592
}
9693

9794
exportasyncfunctioninitIfNotExists():Promise<void>{
98-
consthasGit=awaitversion()
99-
100-
if(!hasGit){
101-
thrownewError('Git must be installed')
102-
}
103-
10495
consthasGitInit=node.exists('.git')
10596
if(!hasGitInit){
10697
awaitinit()

‎typings/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ export interface MachineStateSchema {
7272
Error:{}
7373
LoadStoredTutorial:{}
7474
Start:{}
75-
CheckEmptyWorkspace:{}
75+
ValidateSetup:{}
7676
NonEmptyWorkspace:{}
77+
GitNotInstalled:{}
7778
SelectTutorial:{}
7879
SetupNewTutorial:{}
7980
}

‎web-app/src/Routes.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import SelectTutorialPage from './containers/SelectTutorial'
77
importCompletedPagefrom'./containers/Tutorial/CompletedPage'
88
importLevelSummaryPagefrom'./containers/Tutorial/LevelPage'
99
importSelectEmptyWorkspacefrom'./containers/Check/SelectWorkspace'
10+
importGitInstalledfrom'./containers/Check/GitInstalled'
1011

1112
constRoutes=()=>{
1213
const{ context, send, Router, Route}=useRouter()
@@ -26,6 +27,9 @@ const Routes = () => {
2627
<Routepath={['Setup.NonEmptyWorkspace','Setup.RequestEmptyWorkspace']}>
2728
<SelectEmptyWorkspacesend={send}/>
2829
</Route>
30+
<Routepath="Setup.GitNotInstalled">
31+
<GitInstalledsend={send}/>
32+
</Route>
2933
<Routepath="Setup.Error">
3034
<LoadingPagetext="Error"context={context}/>
3135
</Route>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import*asReactfrom'react'
2+
import*asTfrom'typings'
3+
import{css,jsx}from'@emotion/core'
4+
importButtonfrom'../../components/Button'
5+
6+
conststyles={
7+
container:{
8+
padding:'1rem',
9+
},
10+
}
11+
12+
typeProps={
13+
send:(action:T.Action)=>void
14+
}
15+
16+
constGitInstalled=(props:Props)=>{
17+
constonTryAgain=()=>props.send({type:'TRY_AGAIN'})
18+
return(
19+
<divcss={styles.container}>
20+
<h3>Git Not Installed</h3>
21+
<p>
22+
Git is required for CodeRun to run. Git is a free open-source distributed version control system. Basically, Git
23+
helps you easily save your file system changes.
24+
</p>
25+
<p>
26+
<ahref="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git">Learn how to install Git</a>
27+
</p>
28+
<br/>
29+
<Buttontype="secondary"onClick={onTryAgain}>
30+
Check Again
31+
</Button>
32+
</div>
33+
)
34+
}
35+
36+
exportdefaultGitInstalled

‎web-app/src/services/state/actions/editor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ export default (editorSend: any) => ({
7272
clearStorage():void{
7373
editorSend({type:'TUTORIAL_CLEAR'})
7474
},
75-
checkEmptyWorkspace(){
75+
validateSetup(){
7676
editorSend({
77-
type:'EDITOR_CHECK_WORKSPACE',
77+
type:'EDITOR_VALIDATE_SETUP',
7878
})
7979
},
8080
requestWorkspaceSelect(){

‎web-app/src/services/state/machine.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,19 @@ export const createMachine = (options: any) => {
5555
},
5656
Start:{
5757
on:{
58-
NEW_TUTORIAL:'CheckEmptyWorkspace',
58+
NEW_TUTORIAL:'ValidateSetup',
5959
CONTINUE_TUTORIAL:{
6060
target:'#tutorial-level',
6161
actions:['continueConfig'],
6262
},
6363
},
6464
},
65-
CheckEmptyWorkspace:{
66-
onEntry:['checkEmptyWorkspace'],
65+
ValidateSetup:{
66+
onEntry:['validateSetup'],
6767
on:{
68-
IS_EMPTY_WORKSPACE:'SelectTutorial',
6968
NOT_EMPTY_WORKSPACE:'NonEmptyWorkspace',
69+
GIT_NOT_INSTALLED:'GitNotInstalled',
70+
SETUP_VALIDATED:'SelectTutorial',
7071
},
7172
},
7273
NonEmptyWorkspace:{
@@ -75,7 +76,13 @@ export const createMachine = (options: any) => {
7576
target:'NonEmptyWorkspace',
7677
actions:'requestWorkspaceSelect',
7778
},
78-
WORKSPACE_LOADED:'CheckEmptyWorkspace',
79+
WORKSPACE_LOADED:'ValidateSetup',
80+
},
81+
},
82+
// validation 2: git installed
83+
GitNotInstalled:{
84+
on:{
85+
TRY_AGAIN:'ValidateSetup',
7986
},
8087
},
8188
SelectTutorial:{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp