@@ -22,6 +22,7 @@ import {
2222import { copyTfTemplate } from "./scaffold" ;
2323import { build as buildError , log as logError } from "../../lib/errorBuilder" ;
2424import { errorStatusCode } from "../../lib/errorStatusCode" ;
25+ import { exec } from "../../lib/shell" ;
2526
2627interface CommandOptions {
2728 project : string | undefined ;
@@ -146,14 +147,22 @@ export const createGenerated = (projectPath: string): void => {
146147 logger . info ( `Created generated directory: ${ projectPath } ` ) ;
147148} ;
148149
149- export const gitFetchPull = async (
150+ export const gitPull = async (
150151 sourcePath : string ,
151152 safeLoggingUrl : string
152153) : Promise < void > => {
153154 // 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+ }
157166} ;
158167
159168export const gitCheckout = async (
@@ -203,7 +212,7 @@ export const checkRemoteGitExist = async (
203212} ;
204213
205214/**
206- * Creates "generated" directory if it does not already exists
215+ * Attempts to remove cloned repo in ~/.spk/template directory
207216 *
208217 * @param source remote URL for cloning to cache
209218 * @param sourcePath Path to the template folder cache
@@ -222,9 +231,9 @@ export const retryRemoteValidate = async (
222231 createGenerated ( sourcePath ) ;
223232 const git = simpleGit ( ) ;
224233 await gitClone ( git , source , sourcePath ) ;
225- await gitFetchPull ( sourcePath , safeLoggingUrl ) ;
226234 logger . info ( `Checking out template version: ${ version } ` ) ;
227235 await gitCheckout ( sourcePath , version ) ;
236+ await gitPull ( sourcePath , safeLoggingUrl ) ;
228237 logger . info ( `Successfully re-cloned repo` ) ;
229238} ;
230239
@@ -263,15 +272,15 @@ export const validateRemoteSource = async (
263272 ) ;
264273 try {
265274 // Check if .git folder exists in ${sourcePath}, if not, then clone
266- // if already cloned, 'git pull'
267275 if ( fs . existsSync ( path . join ( sourcePath , ".git" ) ) ) {
268- await gitFetchPull ( sourcePath , safeLoggingUrl ) ;
276+ logger . info ( ` ${ source } already cloned. Proceeding with 'git checkout'.` ) ;
269277 } else {
270278 const git = simpleGit ( ) ;
271279 await gitClone ( git , source , sourcePath ) ;
272280 }
273281 // Checkout tagged version
274282 await gitCheckout ( sourcePath , version ) ;
283+ await gitPull ( sourcePath , safeLoggingUrl ) ;
275284 } catch ( err ) {
276285 if ( err instanceof Error ) {
277286 let retry = false ;
0 commit comments