@@ -7,7 +7,7 @@ import { AskpassEnvironment, AskpassManager } from './askpass/askpassManager';
77import { getConfig } from './config' ;
88import { Logger } from './logger' ;
99import { CommitOrdering , DateType , DeepWriteable , ErrorInfo , GitCommit , GitCommitDetails , GitCommitStash , GitConfigLocation , GitFileChange , GitFileStatus , GitPushBranchMode , GitRepoConfig , GitRepoConfigBranches , GitResetMode , GitSignature , GitSignatureStatus , GitStash , GitTagDetails , MergeActionOn , RebaseActionOn , SquashMessageFormat , TagType , Writeable } from './types' ;
10- import { GitExecutable , UNABLE_TO_FIND_GIT_MSG , UNCOMMITTED , abbrevCommit , constructIncompatibleGitVersionMessage , doesVersionMeetRequirement , getPathFromStr , getPathFromUri , openGitTerminal , pathWithTrailingSlash , realpath , resolveSpawnOutput , showErrorMessage } from './utils' ;
10+ import { GitExecutable , GitVersionRequirement , UNABLE_TO_FIND_GIT_MSG , UNCOMMITTED , abbrevCommit , constructIncompatibleGitVersionMessage , doesVersionMeetRequirement , getPathFromStr , getPathFromUri , openGitTerminal , pathWithTrailingSlash , realpath , resolveSpawnOutput , showErrorMessage } from './utils' ;
1111import { Disposable } from './utils/disposable' ;
1212import { Event } from './utils/event' ;
1313
@@ -17,21 +17,15 @@ const INVALID_BRANCH_REGEXP = /^\(.* .*\)$/;
1717const REMOTE_HEAD_BRANCH_REGEXP = / ^ r e m o t e s \/ .* \/ H E A D $ / ;
1818const GIT_LOG_SEPARATOR = 'XX7Nal-YARtTpjCikii9nJxER19D6diSyk-AWkPb' ;
1919
20- export const GIT_CONFIG = {
21- DIFF : {
22- GUI_TOOL : 'diff.guitool' ,
23- TOOL : 'diff.tool'
24- } ,
25- REMOTE : {
26- PUSH_DEFAULT : 'remote.pushdefault'
27- } ,
28- USER : {
29- EMAIL : 'user.email' ,
30- NAME : 'user.name'
31- }
32- } ;
20+ export const enum GitConfigKey {
21+ DiffGuiTool = 'diff.guitool' ,
22+ DiffTool = 'diff.tool' ,
23+ RemotePushDefault = 'remote.pushdefault' ,
24+ UserEmail = 'user.email' ,
25+ UserName = 'user.name'
26+ }
3327
34- const GPG_STATUS_CODE_PARSING_DETAILS : { [ statusCode : string ] : GpgStatusCodeParsingDetails } = {
28+ const GPG_STATUS_CODE_PARSING_DETAILS : Readonly < { [ statusCode : string ] : GpgStatusCodeParsingDetails } > = {
3529 'GOODSIG' : { status : GitSignatureStatus . GoodAndValid , uid : true } ,
3630 'BADSIG' : { status : GitSignatureStatus . Bad , uid : true } ,
3731 'ERRSIG' : { status : GitSignatureStatus . CannotBeChecked , uid : false } ,
@@ -95,9 +89,9 @@ export class DataSource extends Disposable {
9589 * Set the Git executable used by the DataSource.
9690 * @param gitExecutable The Git executable.
9791 */
98- public setGitExecutable ( gitExecutable : GitExecutable | null ) {
92+ private setGitExecutable ( gitExecutable : GitExecutable | null ) {
9993 this . gitExecutable = gitExecutable ;
100- this . gitExecutableSupportsGpgInfo = gitExecutable !== null ? doesVersionMeetRequirement ( gitExecutable . version , '2.4.0' ) : false ;
94+ this . gitExecutableSupportsGpgInfo = gitExecutable !== null && doesVersionMeetRequirement ( gitExecutable . version , GitVersionRequirement . GpgInfo ) ;
10195 this . generateGitCommandFormats ( ) ;
10296 }
10397
@@ -314,22 +308,22 @@ export class DataSource extends Disposable {
314308 return {
315309 config : {
316310 branches : branches ,
317- diffTool : getConfigValue ( consolidatedConfigs , GIT_CONFIG . DIFF . TOOL ) ,
318- guiDiffTool : getConfigValue ( consolidatedConfigs , GIT_CONFIG . DIFF . GUI_TOOL ) ,
319- pushDefault : getConfigValue ( consolidatedConfigs , GIT_CONFIG . REMOTE . PUSH_DEFAULT ) ,
311+ diffTool : getConfigValue ( consolidatedConfigs , GitConfigKey . DiffTool ) ,
312+ guiDiffTool : getConfigValue ( consolidatedConfigs , GitConfigKey . DiffGuiTool ) ,
313+ pushDefault : getConfigValue ( consolidatedConfigs , GitConfigKey . RemotePushDefault ) ,
320314 remotes : remotes . map ( ( remote ) => ( {
321315 name : remote ,
322316 url : getConfigValue ( localConfigs , 'remote.' + remote + '.url' ) ,
323317 pushUrl : getConfigValue ( localConfigs , 'remote.' + remote + '.pushurl' )
324318 } ) ) ,
325319 user : {
326320 name : {
327- local : getConfigValue ( localConfigs , GIT_CONFIG . USER . NAME ) ,
328- global : getConfigValue ( globalConfigs , GIT_CONFIG . USER . NAME )
321+ local : getConfigValue ( localConfigs , GitConfigKey . UserName ) ,
322+ global : getConfigValue ( globalConfigs , GitConfigKey . UserName )
329323 } ,
330324 email : {
331- local : getConfigValue ( localConfigs , GIT_CONFIG . USER . EMAIL ) ,
332- global : getConfigValue ( globalConfigs , GIT_CONFIG . USER . EMAIL )
325+ local : getConfigValue ( localConfigs , GitConfigKey . UserEmail ) ,
326+ global : getConfigValue ( globalConfigs , GitConfigKey . UserEmail )
333327 }
334328 }
335329 } ,
@@ -503,8 +497,8 @@ export class DataSource extends Disposable {
503497 * @returns The tag details.
504498 */
505499 public getTagDetails ( repo : string , tagName : string ) : Promise < GitTagDetailsData > {
506- if ( this . gitExecutable !== null && ! doesVersionMeetRequirement ( this . gitExecutable . version , '1.7.8' ) ) {
507- return Promise . resolve ( { details : null , error : constructIncompatibleGitVersionMessage ( this . gitExecutable , '1.7.8' , 'retrieving Tag Details' ) } ) ;
500+ if ( this . gitExecutable !== null && ! doesVersionMeetRequirement ( this . gitExecutable . version , GitVersionRequirement . TagDetails ) ) {
501+ return Promise . resolve ( { details : null , error : constructIncompatibleGitVersionMessage ( this . gitExecutable , GitVersionRequirement . TagDetails , 'retrieving Tag Details' ) } ) ;
508502 }
509503
510504 const ref = 'refs/tags/' + tagName ;
@@ -758,8 +752,8 @@ export class DataSource extends Disposable {
758752 if ( pruneTags ) {
759753 if ( ! prune ) {
760754 return Promise . resolve ( 'In order to Prune Tags, pruning must also be enabled when fetching from ' + ( remote !== null ? 'a remote' : 'remote(s)' ) + '.' ) ;
761- } else if ( this . gitExecutable !== null && ! doesVersionMeetRequirement ( this . gitExecutable . version , '2.17.0' ) ) {
762- return Promise . resolve ( constructIncompatibleGitVersionMessage ( this . gitExecutable , '2.17.0' , 'pruning tags when fetching' ) ) ;
755+ } else if ( this . gitExecutable !== null && ! doesVersionMeetRequirement ( this . gitExecutable . version , GitVersionRequirement . FetchAndPruneTags ) ) {
756+ return Promise . resolve ( constructIncompatibleGitVersionMessage ( this . gitExecutable , GitVersionRequirement . FetchAndPruneTags , 'pruning tags when fetching' ) ) ;
763757 }
764758 args . push ( '--prune-tags' ) ;
765759 }
@@ -1139,23 +1133,23 @@ export class DataSource extends Disposable {
11391133 /**
11401134 * Set a configuration value for a repository.
11411135 * @param repo The path of the repository.
1142- * @param key The key to be set.
1136+ * @param key The Git Config Key to be set.
11431137 * @param value The value to be set.
11441138 * @param location The location where the configuration value should be set.
11451139 * @returns The ErrorInfo from the executed command.
11461140 */
1147- public setConfigValue ( repo : string , key : string , value : string , location : GitConfigLocation ) {
1141+ public setConfigValue ( repo : string , key : GitConfigKey , value : string , location : GitConfigLocation ) {
11481142 return this . runGitCommand ( [ 'config' , '--' + location , key , value ] , repo ) ;
11491143 }
11501144
11511145 /**
11521146 * Unset a configuration value for a repository.
11531147 * @param repo The path of the repository.
1154- * @param key The key to be unset.
1148+ * @param key The Git Config Key to be unset.
11551149 * @param location The location where the configuration value should be unset.
11561150 * @returns The ErrorInfo from the executed command.
11571151 */
1158- public unsetConfigValue ( repo : string , key : string , location : GitConfigLocation ) {
1152+ public unsetConfigValue ( repo : string , key : GitConfigKey , location : GitConfigLocation ) {
11591153 return this . runGitCommand ( [ 'config' , '--' + location , '--unset-all' , key ] , repo ) ;
11601154 }
11611155
@@ -1236,8 +1230,8 @@ export class DataSource extends Disposable {
12361230 public pushStash ( repo : string , message : string , includeUntracked : boolean ) : Promise < ErrorInfo > {
12371231 if ( this . gitExecutable === null ) {
12381232 return Promise . resolve ( UNABLE_TO_FIND_GIT_MSG ) ;
1239- } else if ( ! doesVersionMeetRequirement ( this . gitExecutable . version , '2.13.2' ) ) {
1240- return Promise . resolve ( constructIncompatibleGitVersionMessage ( this . gitExecutable , '2.13.2' ) ) ;
1233+ } else if ( ! doesVersionMeetRequirement ( this . gitExecutable . version , GitVersionRequirement . PushStash ) ) {
1234+ return Promise . resolve ( constructIncompatibleGitVersionMessage ( this . gitExecutable , GitVersionRequirement . PushStash ) ) ;
12411235 }
12421236
12431237 let args = [ 'stash' , 'push' ] ;
@@ -1994,6 +1988,6 @@ interface GitTagDetailsData {
19941988}
19951989
19961990interface GpgStatusCodeParsingDetails {
1997- status : GitSignatureStatus ,
1998- uid : boolean
1991+ readonly status : GitSignatureStatus ,
1992+ readonly uid : boolean
19991993}
0 commit comments