Changing autofetch to a string config which has "current", "all" and (#111090)

This commit is contained in:
Jason Williams 2020-12-11 05:54:21 +00:00 committed by GitHub
parent 39f78228fa
commit 83f43bee1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 7 deletions

View file

@ -1644,7 +1644,17 @@
"default": true
},
"git.autofetch": {
"type": "boolean",
"anyOf": [
{
"type": "boolean"
},
{
"type": "string",
"enum": [
"all"
]
}
],
"scope": "resource",
"description": "%config.autofetch%",
"default": false,

View file

@ -97,7 +97,7 @@
"config.autoRepositoryDetection.subFolders": "Scan for subfolders of the currently opened folder.",
"config.autoRepositoryDetection.openEditors": "Scan for parent folders of open files.",
"config.autorefresh": "Whether auto refreshing is enabled.",
"config.autofetch": "When enabled, commits will automatically be fetched from the default remote of the current Git repository.",
"config.autofetch": "When set to true, commits will automatically be fetched from the default remote of the current Git repository. Setting to `all` will fetch from all remotes",
"config.autofetchPeriod": "Duration in seconds between each automatic git fetch, when `git.autofetch` is enabled.",
"config.confirmSync": "Confirm before synchronizing git repositories.",
"config.countBadge": "Controls the Git count badge.",

View file

@ -23,6 +23,7 @@ export class AutoFetcher {
private onDidChange = this._onDidChange.event;
private _enabled: boolean = false;
private _fetchAll: boolean = false;
get enabled(): boolean { return this._enabled; }
set enabled(enabled: boolean) { this._enabled = enabled; this._onDidChange.fire(enabled); }
@ -70,10 +71,20 @@ export class AutoFetcher {
private onConfiguration(): void {
const gitConfig = workspace.getConfiguration('git', Uri.file(this.repository.root));
if (gitConfig.get<boolean>('autofetch') === false) {
this.disable();
} else {
this.enable();
switch (gitConfig.get<boolean | 'all'>('autofetch')) {
case true:
this._fetchAll = false;
this.enable();
break;
case 'all':
this._fetchAll = true;
this.enable();
break;
case false:
default:
this._fetchAll = false;
this.disable();
break;
}
}
@ -99,7 +110,11 @@ export class AutoFetcher {
}
try {
await this.repository.fetchDefault({ silent: true });
if (this._fetchAll) {
await this.repository.fetchAll();
} else {
await this.repository.fetchDefault({ silent: true });
}
} catch (err) {
if (err.gitErrorCode === GitErrorCodes.AuthenticationFailed) {
this.disable();