@@ -113,19 +113,20 @@ export default function githubPagesDeployRun(options: GithubPagesDeployOptions,
113
113
114
114
function createGitHubRepoIfNeeded ( ) {
115
115
return execPromise ( 'git remote -v' )
116
- . then ( function ( stdout ) {
117
- if ( ! / o r i g i n \s + ( h t t p s : \/ \/ | g i t @ ) g i t h u b \. c o m / m. test ( stdout ) ) {
118
- return createGithubRepoTask . run ( createGithubRepoOptions )
119
- . then ( ( ) => {
120
- // only push starting branch if it's not the destinationBranch
121
- // this happens commonly when using github user pages, since
122
- // they require the destination branch to be 'master'
123
- if ( destinationBranch !== initialBranch ) {
124
- execPromise ( `git push -u origin ${ initialBranch } ` ) ;
125
- }
126
- } ) ;
127
- }
128
- } ) ;
116
+ . then ( function ( stdout ) {
117
+ if ( ! / o r i g i n \s + ( h t t p s : \/ \/ | g i t @ ) g i t h u b \. c o m / m. test ( stdout ) ) {
118
+ return createGithubRepoTask . run ( createGithubRepoOptions )
119
+ . then ( ( ) => generateRemoteUrl ( ) )
120
+ . then ( ( upstream : string ) => {
121
+ // only push starting branch if it's not the destinationBranch
122
+ // this happens commonly when using github user pages, since
123
+ // they require the destination branch to be 'master'
124
+ if ( destinationBranch !== initialBranch ) {
125
+ execPromise ( `git push -u ${ upstream } ${ initialBranch } ` ) ;
126
+ }
127
+ } ) ;
128
+ }
129
+ } ) ;
129
130
}
130
131
131
132
function checkoutGhPages ( ) {
@@ -191,30 +192,57 @@ export default function githubPagesDeployRun(options: GithubPagesDeployOptions,
191
192
}
192
193
193
194
function pushToGitRepo ( ) {
194
- return execPromise ( `git push origin ${ ghPagesBranch } :${ destinationBranch } ` )
195
- . catch ( ( err ) => returnStartingBranch ( )
196
- . catch ( ( ) => Promise . reject ( err ) ) ) ;
195
+ return generateRemoteUrl ( )
196
+ . then ( upstream => {
197
+ return execPromise ( `git push ${ upstream } ${ ghPagesBranch } :${ destinationBranch } ` ) ;
198
+ } )
199
+ . catch ( ( err ) => returnStartingBranch ( )
200
+ . catch ( ( ) => Promise . reject ( err ) ) ) ;
197
201
}
198
202
199
203
function printProjectUrl ( ) {
200
- return execPromise ( 'git remote -v' )
201
- . then ( ( stdout ) => {
202
- let match = stdout . match ( / o r i g i n \s + (?: h t t p s : \/ \/ | g i t @ ) g i t h u b \. c o m (?: \: | \/ ) ( [ ^ \/ ] + ) / m) ;
203
- let userName = match [ 1 ] . toLowerCase ( ) ;
204
- let url = `https://${ userName } .github.io/${ options . userPage ? '' : ( baseHref + '/' ) } ` ;
205
- ui . writeLine ( chalk . green ( `Deployed! Visit ${ url } ` ) ) ;
206
- ui . writeLine ( 'Github pages might take a few minutes to show the deployed site.' ) ;
207
- } ) ;
204
+ return getUsernameFromGitOrigin ( )
205
+ . then ( ( userName ) => {
206
+ let url = `https://${ userName } .github.io/${ options . userPage ? '' : ( baseHref + '/' ) } ` ;
207
+ ui . writeLine ( chalk . green ( `Deployed! Visit ${ url } ` ) ) ;
208
+ ui . writeLine ( 'Github pages might take a few minutes to show the deployed site.' ) ;
209
+ } ) ;
208
210
}
209
211
210
212
function failGracefully ( error : Error ) {
211
213
if ( error && ( / g i t c l e a n / . test ( error . message ) || / P e r m i s s i o n d e n i e d / . test ( error . message ) ) ) {
212
214
ui . writeLine ( error . message ) ;
213
215
let msg = 'There was a permissions error during git file operations, ' +
214
- 'please close any open project files/folders and try again.' ;
216
+ 'please close any open project files/folders and try again.' ;
217
+ msg += `\nYou might also need to return to the ${ initialBranch } branch manually.` ;
215
218
return Promise . reject ( new SilentError ( msg . concat ( branchErrMsg ) ) ) ;
216
219
} else {
217
220
return Promise . reject ( error ) ;
218
221
}
219
222
}
223
+
224
+ function generateRemoteUrl ( ) : Promise < String > {
225
+ if ( createGithubRepoOptions . ghToken && createGithubRepoOptions . ghUsername ) {
226
+ return Promise . resolve ( `https://${ createGithubRepoOptions . ghToken } @github.com/` +
227
+ `${ createGithubRepoOptions . ghUsername } /${ createGithubRepoOptions . projectName } .git` ) ;
228
+ }
229
+
230
+ if ( createGithubRepoOptions . ghToken && ! createGithubRepoOptions . ghUsername ) {
231
+ return getUsernameFromGitOrigin ( )
232
+ . then ( username => {
233
+ return Promise . resolve ( `https://${ createGithubRepoOptions . ghToken } @github.com/` +
234
+ `${ username } /${ createGithubRepoOptions . projectName } .git` ) ;
235
+ } ) ;
236
+ }
237
+
238
+ return Promise . resolve ( 'origin' ) ;
239
+ }
240
+
241
+ function getUsernameFromGitOrigin ( ) : Promise < String > {
242
+ return execPromise ( 'git remote -v' )
243
+ . then ( ( stdout ) => {
244
+ let match = stdout . match ( / o r i g i n \s + (?: h t t p s : \/ \/ | g i t @ ) g i t h u b \. c o m (?: \: | \/ ) ( [ ^ \/ ] + ) / m) ;
245
+ return match [ 1 ] . toLowerCase ( ) ;
246
+ } ) ;
247
+ }
220
248
}
0 commit comments