File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,6 +19,9 @@ export class Git {
1919 private static _hasGit : boolean | undefined = undefined ;
2020 private static _gitPath : string | undefined ;
2121
22+ /**
23+ * Returns the path to the git binary if git is found. If git can't be found, return undefined.
24+ */
2225 public static getGitPath ( ) : string | undefined {
2326 if ( Git . _hasGit === undefined ) {
2427 const command : string = process . platform === 'win32' ? 'where' : 'which' ;
@@ -33,8 +36,15 @@ export class Git {
3336 return Git . _gitPath ;
3437 }
3538
36- public static detectIfGitIsSupported ( ) : boolean {
37- if ( Git . getGitPath ( ) ) { // Do we even have a git binary?
39+ public static isGitPresent ( ) : boolean {
40+ return ! ! Git . getGitPath ( ) ;
41+ }
42+
43+ /**
44+ * Checks if git is supported and if the current path is under a git working tree.
45+ */
46+ public static isPathUnderGitWorkingTree ( ) : boolean {
47+ if ( Git . isGitPresent ( ) ) { // Do we even have a git binary?
3848 try {
3949 return ! ! gitInfo ( ) . sha ;
4050 } catch ( e ) {
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ export class PackageChangeAnalyzer {
2424
2525 public constructor ( rushConfiguration : RushConfiguration ) {
2626 this . _rushConfiguration = rushConfiguration ;
27- this . _isGitSupported = Git . detectIfGitIsSupported ( ) ;
27+ this . _isGitSupported = Git . isPathUnderGitWorkingTree ( ) ;
2828 this . _data = this . _getData ( ) ;
2929 }
3030
Original file line number Diff line number Diff line change @@ -10,9 +10,8 @@ import { Utilities } from '../../utilities/Utilities';
1010import { Git } from '../Git' ;
1111
1212export class GitEmailPolicy {
13- public static validate ( rushConfiguration : RushConfiguration ) : void {
14- const gitPath : string | undefined = Git . getGitPath ( ) ;
15- if ( ! gitPath ) {
13+ public static validate ( rushConfiguration : RushConfiguration ) : void {
14+ if ( ! Git . isGitPresent ( ) ) {
1615 // Git isn't present, so the git policy doesn't apply
1716 return ;
1817 }
@@ -25,7 +24,6 @@ export class GitEmailPolicy {
2524 console . log ( colors . red ( 'Aborting, so you can go fix your settings. (Or use --bypass-policy to skip.)' ) ) ;
2625 throw e ;
2726 } else {
28- console . log ( colors . red ( `An unexpected error occurred: ${ e } ` ) ) ;
2927 throw e ;
3028 }
3129 }
@@ -50,6 +48,7 @@ export class GitEmailPolicy {
5048 // Show the user's name as well.
5149 // Ex. "Mr. Example <mr@example.com>"
5250 let fancyEmail : string = colors . cyan ( userEmail ) ;
51+ const gitPath : string = Git . getGitPath ( ) ! ;
5352 try {
5453 const userName : string = Utilities . executeCommandAndCaptureOutput (
5554 gitPath ,
You can’t perform that action at this time.
0 commit comments