@@ -109,11 +109,6 @@ export interface IInstallManagerOptions {
109109 * The variant to consider when performing installations and validating shrinkwrap updates.
110110 */
111111 variant ?: string | undefined ;
112-
113- /**
114- * Whether to copy over git hooks into the git config when installing.
115- */
116- withHooks : boolean ;
117112}
118113
119114/**
@@ -264,22 +259,30 @@ export class InstallManager {
264259
265260 ApprovedPackagesChecker . rewriteConfigFiles ( this . _rushConfiguration ) ;
266261
267- if ( options . withHooks ) {
268- const source : string = path . join ( this . _rushConfiguration . commonFolder , 'git-hooks' ) ;
269- const destination : string = path . join ( this . _rushConfiguration . rushJsonFolder , FolderConstants . Git , 'hooks' ) ;
262+ // Git hooks are only installed if the repo opts in by including files in /common/git-hooks
263+ const hookSource : string = path . join ( this . _rushConfiguration . commonFolder , 'git-hooks' ) ;
264+ const hookDestination : string = path . join ( this . _rushConfiguration . rushJsonFolder , FolderConstants . Git , 'hooks' ) ;
265+ if ( FileSystem . exists ( hookSource ) ) {
266+ console . log ( os . EOL + colors . bold ( 'Detected /common/git-hooks, clearing and reinstalling Git hooks' ) ) ;
267+ const hookFilenames : Array < string > = FileSystem . readFolder ( hookSource ) ;
270268
271- if ( FileSystem . exists ( source ) && FileSystem . exists ( destination ) ) {
272- FileSystem . readFolder ( source ) . forEach ( filename => {
269+ if ( hookFilenames . length === 0 ) {
270+ console . log ( colors . yellow ( 'Warning - You have not added any git hooks yet, skipping for now' ) ) ;
273271
274- const match : RegExpMatchArray | null = filename . match ( / [ a - z \- ] + / ) ;
272+ } else {
273+ // Clear the currently installed git hooks and install fresh copies
274+ FileSystem . ensureEmptyFolder ( hookDestination ) ;
275+ hookFilenames . forEach ( filename => {
276+
277+ const match : RegExpMatchArray | null = filename . match ( / ^ [ a - z \- ] + / ) ;
275278 if ( match !== null ) {
279+ console . log ( `Installing hook ${ match [ 0 ] } ` ) ;
276280 FileSystem . copyFile ( {
277- sourcePath : path . join ( source , filename ) ,
278- destinationPath : path . join ( destination , match [ 0 ] )
281+ sourcePath : path . join ( hookSource , filename ) ,
282+ destinationPath : path . join ( hookDestination , match [ 0 ] )
279283 } ) ;
280- FileSystem . changePosixModeBits ( path . join ( destination , match [ 0 ] ) , PosixModeBits . UserExecute ) ;
284+ FileSystem . changePosixModeBits ( path . join ( hookDestination , match [ 0 ] ) , PosixModeBits . UserExecute ) ;
281285 }
282-
283286 } ) ;
284287 }
285288 }
@@ -1001,7 +1004,7 @@ export class InstallManager {
10011004
10021005 private _queryIfReleaseIsPublished ( registryUrl : string ) : Promise < boolean > {
10031006 let queryUrl : string = registryUrl ;
1004- if ( queryUrl [ - 1 ] !== '/' ) {
1007+ if ( queryUrl [ - 1 ] !== '/' ) {
10051008 queryUrl += '/' ;
10061009 }
10071010 // Note that the "@" symbol does not normally get URL-encoded
0 commit comments