@@ -26,33 +26,44 @@ import type { Config as GitConfig, Options as GitOptions } from './types.js';
26
26
27
27
export default class GitGenerator extends BaseGenerator < GitConfig , GitOptions > {
28
28
gitInitialized ! : boolean ;
29
- skipGit ! : boolean ;
30
- forceGit ! : boolean ;
31
29
existingRepository ! : boolean ;
32
- commitMsg ! : string ;
33
30
34
31
async beforeQueue ( ) {
35
32
if ( ! this . fromBlueprint ) {
36
33
await this . composeWithBlueprints ( ) ;
37
34
}
38
35
}
39
36
37
+ async initializeGitRepository ( ) {
38
+ try {
39
+ const git = this . createGit ( ) ;
40
+ if ( await git . checkIsRepo ( ) ) {
41
+ if ( await git . checkIsRepo ( 'root' as any ) ) {
42
+ this . log . info ( 'Using existing git repository.' ) ;
43
+ } else {
44
+ this . log . info ( 'Using existing git repository at parent folder.' ) ;
45
+ }
46
+ this . existingRepository = true ;
47
+ } else if ( await git . init ( ) ) {
48
+ this . log . ok ( 'Git repository initialized.' ) ;
49
+ }
50
+ this . gitInitialized = true ;
51
+ } catch ( error ) {
52
+ this . log . warn ( `Failed to initialize Git repository.\n ${ error } ` ) ;
53
+ }
54
+ }
55
+
40
56
get initializing ( ) {
41
57
return this . asInitializingTaskGroup ( {
42
58
async checkGit ( ) {
43
- if ( ! this . skipGit ) {
59
+ if ( ! this . options . skipGit ) {
44
60
const gitInstalled = ( await this . createGit ( ) . version ( ) ) . installed ;
45
61
if ( ! gitInstalled ) {
46
62
this . log . warn ( 'Git repository will not be created, as Git is not installed on your system' ) ;
47
- this . skipGit = true ;
63
+ this . options . skipGit = true ;
48
64
}
49
65
}
50
66
} ,
51
- async initializeMonorepository ( ) {
52
- if ( ! this . skipGit && this . jhipsterConfig . monorepository ) {
53
- await this . initializeGitRepository ( ) ;
54
- }
55
- } ,
56
67
} ) ;
57
68
}
58
69
@@ -63,7 +74,7 @@ export default class GitGenerator extends BaseGenerator<GitConfig, GitOptions> {
63
74
get preparing ( ) {
64
75
return this . asPreparingTaskGroup ( {
65
76
async preparing ( ) {
66
- if ( ! this . skipGit ) {
77
+ if ( ! this . options . skipGit ) {
67
78
// Force write .yo-rc.json to disk, it's used to check if the application is regenerated
68
79
this . jhipsterConfig . monorepository ??= undefined ;
69
80
}
@@ -91,7 +102,7 @@ export default class GitGenerator extends BaseGenerator<GitConfig, GitOptions> {
91
102
return this . asPostWritingTaskGroup ( {
92
103
/** Husky commit hook install at install priority requires git to be initialized */
93
104
async initGitRepo ( ) {
94
- if ( ! this . skipGit && ! this . jhipsterConfig . monorepository ) {
105
+ if ( ! this . options . skipGit && ! this . jhipsterConfig . monorepository ) {
95
106
await this . initializeGitRepository ( ) ;
96
107
}
97
108
} ,
@@ -106,25 +117,26 @@ export default class GitGenerator extends BaseGenerator<GitConfig, GitOptions> {
106
117
return this . asEndTaskGroup ( {
107
118
/** Initial commit to git repository after package manager install for package-lock.json */
108
119
async gitCommit ( ) {
109
- if ( this . skipGit ) return ;
120
+ if ( this . options . skipGit ) return ;
110
121
if ( ! this . gitInitialized ) {
111
122
this . log . warn ( 'The generated application could not be committed to Git, as a Git repository could not be initialized.' ) ;
112
123
return ;
113
124
}
114
125
115
126
const commitFiles = async ( ) => {
116
- this . debug ( 'Committing files to git' ) ;
127
+ this . log . debug ( 'Committing files to git' ) ;
117
128
const git = this . createGit ( ) ;
118
129
const repositoryRoot = await git . revparse ( [ '--show-toplevel' ] ) ;
130
+ const msg = await git . log ( [ '-n' , '1' ] ) . catch ( ( ) => ( { total : 0 } ) ) ;
119
131
const result = await git . log ( [ '-n' , '1' , '--' , '.yo-rc.json' ] ) . catch ( ( ) => ( { total : 0 } ) ) ;
120
132
const existingApplication = result . total > 0 ;
121
- if ( existingApplication && ! this . forceGit ) {
133
+ if ( existingApplication && ! this . options . forceGit ) {
122
134
this . log . info (
123
135
`Found .yo-rc.json in Git from ${ repositoryRoot } . So we assume this is application regeneration. Therefore automatic Git commit is not done. You can do Git commit manually.` ,
124
136
) ;
125
137
return ;
126
138
}
127
- if ( ! this . forceGit ) {
139
+ if ( ! this . options . forceGit ) {
128
140
const statusResult = await git . status ( ) ;
129
141
if ( statusResult . staged . length > 0 ) {
130
142
this . log . verboseInfo ( `The repository ${ repositoryRoot } has staged files, skipping commit.` ) ;
@@ -133,7 +145,7 @@ export default class GitGenerator extends BaseGenerator<GitConfig, GitOptions> {
133
145
}
134
146
try {
135
147
let commitMsg =
136
- this . commitMsg ??
148
+ this . options . commitMsg ??
137
149
( existingApplication
138
150
? `Regenerated ${ this . jhipsterConfig . baseName } using generator-jhipster@${ this . jhipsterConfig . jhipsterVersion } `
139
151
: `Initial version of ${ this . jhipsterConfig . baseName } generated by generator-jhipster@${ this . jhipsterConfig . jhipsterVersion } ` ) ;
@@ -163,23 +175,4 @@ export default class GitGenerator extends BaseGenerator<GitConfig, GitOptions> {
163
175
get [ BaseGenerator . END ] ( ) {
164
176
return this . delegateTasksToBlueprint ( ( ) => this . end ) ;
165
177
}
166
-
167
- async initializeGitRepository ( ) {
168
- try {
169
- const git = this . createGit ( ) ;
170
- if ( await git . checkIsRepo ( ) ) {
171
- if ( await git . checkIsRepo ( 'root' as any ) ) {
172
- this . log . info ( 'Using existing git repository.' ) ;
173
- } else {
174
- this . log . info ( 'Using existing git repository at parent folder.' ) ;
175
- }
176
- this . existingRepository = true ;
177
- } else if ( await git . init ( ) ) {
178
- this . log . ok ( 'Git repository initialized.' ) ;
179
- }
180
- this . gitInitialized = true ;
181
- } catch ( error ) {
182
- this . log . warn ( `Failed to initialize Git repository.\n ${ error } ` ) ;
183
- }
184
- }
185
178
}
0 commit comments