@@ -22,7 +22,7 @@ const spawn = require('react-dev-utils/crossSpawn');
22
22
const { defaultBrowsers } = require ( 'react-dev-utils/browsersHelper' ) ;
23
23
const os = require ( 'os' ) ;
24
24
25
- function insideGitRepository ( ) {
25
+ function isInGitRepository ( ) {
26
26
try {
27
27
execSync ( 'git rev-parse --is-inside-work-tree' , { stdio : 'ignore' } ) ;
28
28
return true ;
@@ -31,7 +31,7 @@ function insideGitRepository() {
31
31
}
32
32
}
33
33
34
- function insideMercurialRepository ( ) {
34
+ function isInMercurialRepository ( ) {
35
35
try {
36
36
execSync ( 'hg --cwd . root' , { stdio : 'ignore' } ) ;
37
37
return true ;
@@ -40,22 +40,36 @@ function insideMercurialRepository() {
40
40
}
41
41
}
42
42
43
- function tryGitInit ( ) {
43
+ function tryGitInit ( appPath ) {
44
+ let didInit = false ;
44
45
try {
45
46
execSync ( 'git --version' , { stdio : 'ignore' } ) ;
46
-
47
- if ( insideGitRepository ( ) || insideMercurialRepository ( ) ) {
47
+ if ( isInGitRepository ( ) || isInMercurialRepository ( ) ) {
48
48
return false ;
49
49
}
50
50
51
51
execSync ( 'git init' , { stdio : 'ignore' } ) ;
52
+ didInit = true ;
53
+
52
54
execSync ( 'git add -A' , { stdio : 'ignore' } ) ;
53
55
execSync ( 'git commit -m "Initial commit from Create React App"' , {
54
56
stdio : 'ignore' ,
55
57
} ) ;
56
-
57
58
return true ;
58
59
} catch ( e ) {
60
+ if ( didInit ) {
61
+ // If we successfully initialized but couldn't commit,
62
+ // maybe the commit author config is not set.
63
+ // In the future, we might supply our own committer
64
+ // like Ember CLI does, but for now, let's just
65
+ // remove the Git files to avoid a half-done state.
66
+ try {
67
+ // unlinkSync() doesn't work on directories.
68
+ fs . removeSync ( path . join ( appPath , '.git' ) ) ;
69
+ } catch ( removeErr ) {
70
+ // Ignore.
71
+ }
72
+ }
59
73
return false ;
60
74
}
61
75
}
@@ -172,7 +186,7 @@ module.exports = function(
172
186
}
173
187
}
174
188
175
- if ( tryGitInit ( ) ) {
189
+ if ( tryGitInit ( appPath ) ) {
176
190
console . log ( ) ;
177
191
console . log ( 'Initialized a git repository.' ) ;
178
192
}
0 commit comments