Skip to content

Commit 32d7bcd

Browse files
committed
1 parent f6bef60 commit 32d7bcd

1 file changed

Lines changed: 23 additions & 19 deletions

File tree

extensions/git/src/autofetch.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,35 +35,39 @@ export class AutoFetcher {
3535
workspace.onDidChangeConfiguration(this.onConfiguration, this, this.disposables);
3636
this.onConfiguration();
3737

38-
const didInformUser = !globalState.get<boolean>(AutoFetcher.DidInformUser);
38+
const onGoodRemoteOperation = filterEvent(repository.onDidRunOperation, ({ operation, error }) => !error && isRemoteOperation(operation));
39+
const onFirstGoodRemoteOperation = onceEvent(onGoodRemoteOperation);
40+
onFirstGoodRemoteOperation(this.onFirstGoodRemoteOperation, this, this.disposables);
41+
}
42+
43+
private async onFirstGoodRemoteOperation(): Promise<void> {
44+
const didInformUser = !this.globalState.get<boolean>(AutoFetcher.DidInformUser);
3945

4046
if (this.enabled && !didInformUser) {
41-
globalState.update(AutoFetcher.DidInformUser, true);
47+
this.globalState.update(AutoFetcher.DidInformUser, true);
4248
}
4349

4450
const shouldInformUser = !this.enabled && didInformUser;
4551

46-
if (shouldInformUser) {
47-
const onGoodRemoteOperation = filterEvent(repository.onDidRunOperation, ({ operation, error }) => !error && isRemoteOperation(operation));
48-
49-
this.disposables.push(onceEvent(onGoodRemoteOperation)(async () => {
50-
const yes: MessageItem = { title: localize('yes', "Yes") };
51-
const no: MessageItem = { isCloseAffordance: true, title: localize('no', "No") };
52-
const askLater: MessageItem = { title: localize('not now', "Not Now") };
53-
const result = await window.showInformationMessage(localize('suggest auto fetch', "Would you like to enable auto fetching of Git repositories?"), yes, no, askLater);
52+
if (!shouldInformUser) {
53+
return;
54+
}
5455

55-
if (result === askLater) {
56-
return;
57-
}
56+
const yes: MessageItem = { title: localize('yes', "Yes") };
57+
const no: MessageItem = { isCloseAffordance: true, title: localize('no', "No") };
58+
const askLater: MessageItem = { title: localize('not now', "Not Now") };
59+
const result = await window.showInformationMessage(localize('suggest auto fetch', "Would you like to enable auto fetching of Git repositories?"), yes, no, askLater);
5860

59-
if (result === yes) {
60-
const gitConfig = workspace.getConfiguration('git');
61-
gitConfig.update('autofetch', true, ConfigurationTarget.Global);
62-
}
61+
if (result === askLater) {
62+
return;
63+
}
6364

64-
globalState.update(AutoFetcher.DidInformUser, true);
65-
}));
65+
if (result === yes) {
66+
const gitConfig = workspace.getConfiguration('git');
67+
gitConfig.update('autofetch', true, ConfigurationTarget.Global);
6668
}
69+
70+
this.globalState.update(AutoFetcher.DidInformUser, true);
6771
}
6872

6973
private onConfiguration(): void {

0 commit comments

Comments
 (0)