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

Commit2349c6a

Browse files
authored
Merge pull requestcoderoad#457 from coderoad/fix/check-git-user-configured
validate git is configured with user.name & email
2 parents34b1e6e +06e5880 commit2349c6a

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

‎src/actions/onValidateSetup.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import*asTfrom'typings'
21
import*asEfrom'typings/error'
32
import{version}from'../services/dependencies'
43
import{checkWorkspaceEmpty}from'../services/workspace'
54
import{send}from'../commands'
5+
import{validateGitConfig}from'../services/git'
66

77
constonValidateSetup=async():Promise<void>=>{
88
try{
@@ -43,6 +43,27 @@ const onValidateSetup = async (): Promise<void> => {
4343
send({type:'VALIDATE_SETUP_FAILED',payload:{ error}})
4444
return
4545
}
46+
47+
constisGitUserNameConfigured=awaitvalidateGitConfig('user.name')
48+
constisGitUserEmailConfigured=awaitvalidateGitConfig('user.email')
49+
if(!isGitUserNameConfigured||!isGitUserEmailConfigured){
50+
letmessage=''
51+
if(!isGitUserNameConfigured)message+='Git user not configured.\n'
52+
if(!isGitUserEmailConfigured)message+='Git email not configured.'
53+
consterror:E.ErrorMessage={
54+
type:'GitUserNotConfigured',
55+
message,
56+
actions:[
57+
{
58+
label:'Check Again',
59+
transition:'RETRY',
60+
},
61+
],
62+
}
63+
send({type:'VALIDATE_SETUP_FAILED',payload:{ error}})
64+
return
65+
}
66+
4667
send({type:'SETUP_VALIDATED'})
4768
}catch(e){
4869
consterror={

‎src/services/git/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,16 @@ export async function commitsExistsByMessage(message: string): Promise<boolean>
191191
returnfalse
192192
}
193193
}
194+
195+
exportasyncfunctionvalidateGitConfig(target:string):Promise<boolean>{
196+
try{
197+
// returns a list of commit hashes
198+
const{ stdout, stderr}=awaitexec({command:`git config${target}`})
199+
if(stderr){
200+
returnfalse
201+
}
202+
return!!stdout.length
203+
}catch(error){
204+
returnfalse
205+
}
206+
}

‎typings/error.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export type ErrorMessageView = 'FULL_PAGE' | 'NOTIFY' | 'NONE'
33
exporttypeErrorMessageType=
44
|'FailedToConnectToGitRepo'
55
|'GitNotFound'
6+
|'GitUserNotConfigured'
67
|'GitProjectAlreadyExists'
78
|'GitRemoteAlreadyExists'
89
|'MissingTutorialDependency'

‎web-app/src/services/errors/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"FailedToConnectToGitRepo":"### Failed to Connect to Git Repo\n\nThere are several possible causes:\n\n- you may not be connected to the internet or have an unstable connection.\n- you may not have access permission to the remote tutorial repo.\n- the remote tutorial repo may not exist at the provided location",
33
"GitNotFound":"### Git Not Found\n\nMake sure you have Git installed.\n\nSee the [Git docs](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) for help.",
4+
"GitUserNotConfigured":"### Git User Not Configured\n\nThe first thing you should do when you install Git is to set your user name and email address. This is important because every Git commit uses this information, and it’s immutably baked into the commits you start creating:\n```shell\ngit config --global user.name\"John Doe\"\ngit config --global user.email johndoe@example.com\n```",
45
"GitProjectAlreadyExists":"### Git Remote Already Exists\n\nHave you started this tutorial before in this workspace? The Git remote already exists.\n\nConsider deleting your `.git` folder and restarting.",
56
"GitRemoteAlreadyExists":"### Git Project Already Exists\n\nCodeRoad requires an empty Git project.\n\nOpen a new workspace to start a tutorial.",
67
"MissingTutorialDependency":"### Missing Tutorial Dependency\n\nThe tutorial cannot run because it a dependency is not yet installed. Install the dependency and click\"Check Again\".",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp