@@ -19,7 +19,9 @@ import {
1919 MapExtensions ,
2020 FileSystem ,
2121 FileConstants ,
22- Sort
22+ Sort ,
23+ FolderConstants ,
24+ PosixModeBits
2325} from '@microsoft/node-core-library' ;
2426
2527import { ApprovedPackagesChecker } from '../logic/ApprovedPackagesChecker' ;
@@ -102,10 +104,16 @@ export interface IInstallManagerOptions {
102104 * If specified when using PNPM, the logs will be in /common/temp/pnpm.log
103105 */
104106 collectLogFile : boolean ;
107+
105108 /**
106109 * The variant to consider when performing installations and validating shrinkwrap updates.
107110 */
108111 variant ?: string | undefined ;
112+
113+ /**
114+ * Whether to copy over git hooks into the git config when installing.
115+ */
116+ withHooks : boolean ;
109117}
110118
111119/**
@@ -178,10 +186,10 @@ export class InstallManager {
178186 private static _collectVersionsForDependencies (
179187 rushConfiguration : RushConfiguration ,
180188 options : {
181- versionsForDependencies : Map < string , Set < string > > ;
182- dependencies : ReadonlyArray < PackageJsonDependency > ;
183- cyclicDependencies : Set < string > ;
184- variant : string | undefined ;
189+ versionsForDependencies : Map < string , Set < string > > ;
190+ dependencies : ReadonlyArray < PackageJsonDependency > ;
191+ cyclicDependencies : Set < string > ;
192+ variant : string | undefined ;
185193 } ) : void {
186194 const {
187195 variant,
@@ -256,6 +264,26 @@ export class InstallManager {
256264
257265 ApprovedPackagesChecker . rewriteConfigFiles ( this . _rushConfiguration ) ;
258266
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' ) ;
270+
271+ if ( FileSystem . exists ( source ) && FileSystem . exists ( destination ) ) {
272+ FileSystem . readFolder ( source ) . forEach ( filename => {
273+
274+ const match : RegExpMatchArray | null = filename . match ( / [ a - z \- ] + / ) ;
275+ if ( match !== null ) {
276+ FileSystem . copyFile ( {
277+ sourcePath : path . join ( source , filename ) ,
278+ destinationPath : path . join ( destination , match [ 0 ] )
279+ } ) ;
280+ FileSystem . changePosixModeBits ( path . join ( destination , match [ 0 ] ) , PosixModeBits . UserExecute ) ;
281+ }
282+
283+ } ) ;
284+ }
285+ }
286+
259287 // Ensure that the package manager is installed
260288 return this . ensureLocalPackageManager ( )
261289 . then ( ( ) => {
@@ -603,8 +631,8 @@ export class InstallManager {
603631 if ( shrinkwrapFile ) {
604632 if ( ! shrinkwrapFile . tryEnsureCompatibleDependency ( packageName , packageVersion ,
605633 rushProject . tempProjectName ) ) {
606- shrinkwrapWarnings . push ( `"${ packageName } " (${ packageVersion } ) required by`
607- + ` "${ rushProject . packageName } "` ) ;
634+ shrinkwrapWarnings . push ( `"${ packageName } " (${ packageVersion } ) required by`
635+ + ` "${ rushProject . packageName } "` ) ;
608636 shrinkwrapIsUpToDate = false ;
609637 }
610638 }
@@ -864,7 +892,7 @@ export class InstallManager {
864892 }
865893
866894 // Run "npm install" in the common folder
867- const installArgs : string [ ] = [ 'install' ] ;
895+ const installArgs : string [ ] = [ 'install' ] ;
868896 this . _pushConfigurationArgs ( installArgs , options ) ;
869897
870898 console . log ( os . EOL + colors . bold ( `Running "${ this . _rushConfiguration . packageManager } install" in`
@@ -991,9 +1019,9 @@ export class InstallManager {
9911019 }
9921020
9931021 return fetch . default ( queryUrl , {
994- headers : headers ,
995- agent : agent
996- } )
1022+ headers : headers ,
1023+ agent : agent
1024+ } )
9971025 . then ( ( response : fetch . Response ) => {
9981026 if ( ! response . ok ) {
9991027 return Promise . reject ( new Error ( 'Failed to query' ) ) ;
@@ -1018,9 +1046,9 @@ export class InstallManager {
10181046 // Make sure the tarball wasn't deleted from the CDN
10191047 headers . set ( 'accept' , '*/*' ) ;
10201048 return fetch . default ( url , {
1021- headers : headers ,
1022- agent : agent
1023- } )
1049+ headers : headers ,
1050+ agent : agent
1051+ } )
10241052 . then < boolean > ( ( response2 : fetch . Response ) => {
10251053 if ( ! response2 . ok ) {
10261054 if ( response2 . status === 404 ) {
@@ -1114,7 +1142,7 @@ export class InstallManager {
11141142 private _syncFile ( sourcePath : string , destinationPath : string ) : void {
11151143 if ( FileSystem . exists ( sourcePath ) ) {
11161144 console . log ( 'Updating ' + destinationPath ) ;
1117- FileSystem . copyFile ( { sourcePath, destinationPath} ) ;
1145+ FileSystem . copyFile ( { sourcePath, destinationPath } ) ;
11181146 } else {
11191147 if ( FileSystem . exists ( destinationPath ) ) {
11201148 console . log ( 'Deleting ' + destinationPath ) ;
0 commit comments