@@ -26,33 +26,44 @@ import type { Config as GitConfig, Options as GitOptions } from './types.js';
2626
2727export default class GitGenerator extends BaseGenerator < GitConfig , GitOptions > {
2828 gitInitialized ! : boolean ;
29- skipGit ! : boolean ;
30- forceGit ! : boolean ;
3129 existingRepository ! : boolean ;
32- commitMsg ! : string ;
3330
3431 async beforeQueue ( ) {
3532 if ( ! this . fromBlueprint ) {
3633 await this . composeWithBlueprints ( ) ;
3734 }
3835 }
3936
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+
4056 get initializing ( ) {
4157 return this . asInitializingTaskGroup ( {
4258 async checkGit ( ) {
43- if ( ! this . skipGit ) {
59+ if ( ! this . options . skipGit ) {
4460 const gitInstalled = ( await this . createGit ( ) . version ( ) ) . installed ;
4561 if ( ! gitInstalled ) {
4662 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 ;
4864 }
4965 }
5066 } ,
51- async initializeMonorepository ( ) {
52- if ( ! this . skipGit && this . jhipsterConfig . monorepository ) {
53- await this . initializeGitRepository ( ) ;
54- }
55- } ,
5667 } ) ;
5768 }
5869
@@ -63,7 +74,7 @@ export default class GitGenerator extends BaseGenerator<GitConfig, GitOptions> {
6374 get preparing ( ) {
6475 return this . asPreparingTaskGroup ( {
6576 async preparing ( ) {
66- if ( ! this . skipGit ) {
77+ if ( ! this . options . skipGit ) {
6778 // Force write .yo-rc.json to disk, it's used to check if the application is regenerated
6879 this . jhipsterConfig . monorepository ??= undefined ;
6980 }
@@ -91,7 +102,7 @@ export default class GitGenerator extends BaseGenerator<GitConfig, GitOptions> {
91102 return this . asPostWritingTaskGroup ( {
92103 /** Husky commit hook install at install priority requires git to be initialized */
93104 async initGitRepo ( ) {
94- if ( ! this . skipGit && ! this . jhipsterConfig . monorepository ) {
105+ if ( ! this . options . skipGit && ! this . jhipsterConfig . monorepository ) {
95106 await this . initializeGitRepository ( ) ;
96107 }
97108 } ,
@@ -106,25 +117,26 @@ export default class GitGenerator extends BaseGenerator<GitConfig, GitOptions> {
106117 return this . asEndTaskGroup ( {
107118 /** Initial commit to git repository after package manager install for package-lock.json */
108119 async gitCommit ( ) {
109- if ( this . skipGit ) return ;
120+ if ( this . options . skipGit ) return ;
110121 if ( ! this . gitInitialized ) {
111122 this . log . warn ( 'The generated application could not be committed to Git, as a Git repository could not be initialized.' ) ;
112123 return ;
113124 }
114125
115126 const commitFiles = async ( ) => {
116- this . debug ( 'Committing files to git' ) ;
127+ this . log . debug ( 'Committing files to git' ) ;
117128 const git = this . createGit ( ) ;
118129 const repositoryRoot = await git . revparse ( [ '--show-toplevel' ] ) ;
130+ const msg = await git . log ( [ '-n' , '1' ] ) . catch ( ( ) => ( { total : 0 } ) ) ;
119131 const result = await git . log ( [ '-n' , '1' , '--' , '.yo-rc.json' ] ) . catch ( ( ) => ( { total : 0 } ) ) ;
120132 const existingApplication = result . total > 0 ;
121- if ( existingApplication && ! this . forceGit ) {
133+ if ( existingApplication && ! this . options . forceGit ) {
122134 this . log . info (
123135 `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.` ,
124136 ) ;
125137 return ;
126138 }
127- if ( ! this . forceGit ) {
139+ if ( ! this . options . forceGit ) {
128140 const statusResult = await git . status ( ) ;
129141 if ( statusResult . staged . length > 0 ) {
130142 this . log . verboseInfo ( `The repository ${ repositoryRoot } has staged files, skipping commit.` ) ;
@@ -133,7 +145,7 @@ export default class GitGenerator extends BaseGenerator<GitConfig, GitOptions> {
133145 }
134146 try {
135147 let commitMsg =
136- this . commitMsg ??
148+ this . options . commitMsg ??
137149 ( existingApplication
138150 ? `Regenerated ${ this . jhipsterConfig . baseName } using generator-jhipster@${ this . jhipsterConfig . jhipsterVersion } `
139151 : `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> {
163175 get [ BaseGenerator . END ] ( ) {
164176 return this . delegateTasksToBlueprint ( ( ) => this . end ) ;
165177 }
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- }
185178}
0 commit comments