diff --git a/extensions/git/package.json b/extensions/git/package.json index 5f4f14737e9991df32060825c3f2c0ddfd8a4c4e..fc995a6e94b00997544160ef3ba72ebb6cc9d144 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -1028,7 +1028,7 @@ "type": "number", "scope": "resource", "description": "%config.autofetchPeriod%", - "default": 3 + "default": 180 }, "git.branchValidationRegex": { "type": "string", diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 118e0f1cd6423b03ade3525db546abad0eae7e44..506f2772f54fd302561a610562de86a93e2257ae 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -68,7 +68,7 @@ "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.autofetchPeriod": "Duration in minutes between each automatic git fetch, when `git.autofetch` is enabled.", + "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 badge counter.", "config.countBadge.all": "Count all changes.", diff --git a/extensions/git/src/autofetch.ts b/extensions/git/src/autofetch.ts index 08a104614d6fa9519a7f3085afe8040399c2c36a..f6c28946620f4542e0c98986dad60ac5a5138d0e 100644 --- a/extensions/git/src/autofetch.ts +++ b/extensions/git/src/autofetch.ts @@ -19,17 +19,13 @@ export class AutoFetcher { private static DidInformUser = 'autofetch.didInformUser'; - private _onDidChange = new EventEmitter(); + private _onDidChange = new EventEmitter(); private onDidChange = this._onDidChange.event; private _enabled: boolean = false; get enabled(): boolean { return this._enabled; } set enabled(enabled: boolean) { this._enabled = enabled; this._onDidChange.fire(enabled); } - private _timeout: number = workspace.getConfiguration('git').get('autofetchPeriod', 3) * 60 * 1000; - private get timeout(): number { return this._timeout; } - private set timeout(minutes: number) { this._timeout = minutes * 60 * 1000; this._onDidChange.fire(minutes); } - private disposables: Disposable[] = []; constructor(private repository: Repository, private globalState: Memento) { @@ -73,19 +69,19 @@ export class AutoFetcher { private onConfiguration(): void { const gitConfig = workspace.getConfiguration('git'); - const minutes = gitConfig.get('autofetchPeriod', 3); - const autofetch = gitConfig.get('autofetch'); - - if (this.timeout !== minutes) { - this.timeout = minutes; - } - if (this.enabled !== autofetch) { - autofetch ? this.enable() : this.disable(); + if (gitConfig.get('autofetch') === false) { + this.disable(); + } else { + this.enable(); } } enable(): void { + if (this.enabled) { + return; + } + this.enabled = true; this.run(); } @@ -114,9 +110,11 @@ export class AutoFetcher { return; } - const timeout = new Promise(c => setTimeout(c, this.timeout)); - const onChanged = eventToPromise(filterEvent(this.onDidChange, () => true)); - await Promise.race([timeout, onChanged]); + const period = workspace.getConfiguration('git').get('autofetchPeriod', 180) * 1000; + const timeout = new Promise(c => setTimeout(c, period)); + const whenDisabled = eventToPromise(filterEvent(this.onDidChange, enabled => !enabled)); + + await Promise.race([timeout, whenDisabled]); } }