@@ -22,6 +22,7 @@ import {
22
22
import { copyTfTemplate } from "./scaffold" ;
23
23
import { build as buildError , log as logError } from "../../lib/errorBuilder" ;
24
24
import { errorStatusCode } from "../../lib/errorStatusCode" ;
25
+ import { exec } from "../../lib/shell" ;
25
26
26
27
interface CommandOptions {
27
28
project : string | undefined ;
@@ -146,14 +147,22 @@ export const createGenerated = (projectPath: string): void => {
146
147
logger . info ( `Created generated directory: ${ projectPath } ` ) ;
147
148
} ;
148
149
149
- export const gitFetchPull = async (
150
+ export const gitPull = async (
150
151
sourcePath : string ,
151
152
safeLoggingUrl : string
152
153
) : Promise < void > => {
153
154
// Make sure we have the latest version of all releases cached locally
154
- await simpleGit ( sourcePath ) . fetch ( "all" ) ;
155
- await simpleGit ( sourcePath ) . pull ( "origin" , "master" ) ;
156
- logger . info ( `${ safeLoggingUrl } already cloned. Performing 'git pull'...` ) ;
155
+ try {
156
+ await exec ( "git" , [ "symbolic-ref" , "HEAD" ] , { cwd : sourcePath } ) ;
157
+ logger . info (
158
+ `${ safeLoggingUrl } already cloned and a git branch is currently checked out. Performing 'git pull'...`
159
+ ) ;
160
+ await simpleGit ( sourcePath ) . pull ( ) ;
161
+ } catch ( err ) {
162
+ logger . info (
163
+ `A git tag is currently checked out. Skipping 'git pull' operation.`
164
+ ) ;
165
+ }
157
166
} ;
158
167
159
168
export const gitCheckout = async (
@@ -203,7 +212,7 @@ export const checkRemoteGitExist = async (
203
212
} ;
204
213
205
214
/**
206
- * Creates "generated" directory if it does not already exists
215
+ * Attempts to remove cloned repo in ~/.spk/template directory
207
216
*
208
217
* @param source remote URL for cloning to cache
209
218
* @param sourcePath Path to the template folder cache
@@ -222,9 +231,9 @@ export const retryRemoteValidate = async (
222
231
createGenerated ( sourcePath ) ;
223
232
const git = simpleGit ( ) ;
224
233
await gitClone ( git , source , sourcePath ) ;
225
- await gitFetchPull ( sourcePath , safeLoggingUrl ) ;
226
234
logger . info ( `Checking out template version: ${ version } ` ) ;
227
235
await gitCheckout ( sourcePath , version ) ;
236
+ await gitPull ( sourcePath , safeLoggingUrl ) ;
228
237
logger . info ( `Successfully re-cloned repo` ) ;
229
238
} ;
230
239
@@ -263,15 +272,15 @@ export const validateRemoteSource = async (
263
272
) ;
264
273
try {
265
274
// Check if .git folder exists in ${sourcePath}, if not, then clone
266
- // if already cloned, 'git pull'
267
275
if ( fs . existsSync ( path . join ( sourcePath , ".git" ) ) ) {
268
- await gitFetchPull ( sourcePath , safeLoggingUrl ) ;
276
+ logger . info ( ` ${ source } already cloned. Proceeding with 'git checkout'.` ) ;
269
277
} else {
270
278
const git = simpleGit ( ) ;
271
279
await gitClone ( git , source , sourcePath ) ;
272
280
}
273
281
// Checkout tagged version
274
282
await gitCheckout ( sourcePath , version ) ;
283
+ await gitPull ( sourcePath , safeLoggingUrl ) ;
275
284
} catch ( err ) {
276
285
if ( err instanceof Error ) {
277
286
let retry = false ;
0 commit comments