Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new sync aware status bar #194

Merged
merged 23 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c4061e7
feat: new sync aware status bar
senyai Nov 21, 2024
d8acedf
refactor: use `updateModelState` to apply side effects
senyai Nov 23, 2024
89cdc31
fix: "refresh" command explicitly refreshes all
senyai Nov 23, 2024
92ca948
test: fix: `fakeFossilStatus` should't be awaited
senyai Nov 23, 2024
02059cf
test: new test for `fossil.refresh`
senyai Nov 23, 2024
1b431a0
refactor: replace "\u2022" with bullet character
senyai Nov 25, 2024
1c67fba
comment: add comment about `branchCommand`
senyai Nov 25, 2024
13b3abf
test: add first status bar tests
senyai Nov 25, 2024
f76d727
fix: await update in `branchChange`
senyai Nov 26, 2024
4153e64
fix: make 'update' command affect branch and changes
senyai Nov 26, 2024
c5ad642
test: add "Branch change is reflected in status bar" test
senyai Nov 26, 2024
f7ae856
fix: don't require opened repository for preview to work
senyai Nov 27, 2024
611deef
fix: missing 'sync' command in the menus
senyai Dec 1, 2024
3ba35b2
refactor: `string` to `RelativePath`
senyai Dec 1, 2024
22e999b
fix: rework sync bar moments
senyai Dec 1, 2024
10f8289
test: add local repository syncing test
senyai Dec 1, 2024
eb9d91a
refactor: remove default "runOperation"
senyai Dec 1, 2024
bbc5c02
tets: add 'nonsensical "change" is ignored' test
senyai Dec 1, 2024
28f77b2
fix: update "autoSyncInterval" docs
senyai Dec 1, 2024
2dd46f3
fix: allow turning off automatic 'fossil sync'
senyai Dec 1, 2024
2988565
refactor: rename statusbar.ts -> statusBar.ts
senyai Dec 1, 2024
96cf0e2
refactor: extract status bar tests into statusBarSuite.ts
senyai Dec 1, 2024
44f9273
dev: ignore "delay" coverage in tests (+4 lines coverage)
senyai Dec 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,18 @@ about cloning from the extension.

* Specifies an explicit `fossil` file path to use.
* This should only be used if `fossil` cannot be found automatically.
* The default behaviour is to search for `fossil` on the PATH.
* The default behavior is to search for `fossil` on the PATH.
* Takes effect immediately.

`fossil.username { string }`

* Specifies an explicit user to use for fossil commits.
* This should only be used if the user is different than the fossil default user.

`fossil.autoSyncInterval { number }`
* The duration, in seconds, between each background `fossil sync` operation.
* 0 to disable.

# Troubleshooting

In general, Fossil designers maintain an abundance of
Expand Down
1 change: 1 addition & 0 deletions docs/dev/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ _Work in progress_.
| fossil.stashPop | Stash Pop | •&nbsp;Main SCM menu<br>•&nbsp;Command palette |
| fossil.stashSave | Stash Push | •&nbsp;Main SCM menu<br>•&nbsp;Command palette |
| fossil.stashSnapshot | Stash Snapshot | •&nbsp;Main SCM menu<br>•&nbsp;Command palette |
| fossil.sync | Sync | •&nbsp;Main SCM menu<br>•&nbsp;Command palette | execute `fossil sync`
| fossil.undo | Undo | •&nbsp;Main SCM menu<br>•&nbsp;Command palette | execute `fossil undo`
| fossil.unstage | Unstage Changes |
| fossil.unstageAll | Unstage All Changes |
Expand Down
25 changes: 18 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@
"category": "Fossil",
"icon": "$(plus)"
},
{
"command": "fossil.sync",
"title": "%command.sync%",
"category": "Fossil"
},
{
"command": "fossil.undo",
"title": "%command.undo%",
Expand Down Expand Up @@ -571,7 +576,7 @@
},
{
"command": "fossil.render",
"when": "fossilOpenRepositoryCount && !isInDiffEditor && resourceExtname =~ /^\\.(md|wiki|pikchr)$/ || fossil.found && resourceScheme == untitled"
"when": "fossil.found && !isInDiffEditor && resourceExtname == '.md' || fossil.found && !isInDiffEditor && resourceExtname =~ /^\\.(md|wiki|pikchr)$/ || fossilOpenRepositoryCount && resourceScheme == untitled"
},
{
"command": "fossil.deleteFiles",
Expand Down Expand Up @@ -630,20 +635,25 @@
"when": "scmProvider == fossil"
},
{
"command": "fossil.pull",
"command": "fossil.sync",
"group": "1_sync@2",
"when": "scmProvider == fossil"
},
{
"command": "fossil.push",
"command": "fossil.pull",
"group": "1_sync@3",
"when": "scmProvider == fossil"
},
{
"command": "fossil.pushTo",
"command": "fossil.push",
"group": "1_sync@4",
"when": "scmProvider == fossil"
},
{
"command": "fossil.pushTo",
"group": "1_sync@5",
"when": "scmProvider == fossil"
},
{
"command": "fossil.undo",
"group": "3_commit@0",
Expand Down Expand Up @@ -1036,10 +1046,11 @@
"configuration": {
"title": "Fossil",
"properties": {
"fossil.autoInOutInterval": {
"fossil.autoSyncInterval": {
"type": "number",
"description": "%config.autoInOutInterval%",
"default": 180
"description": "%config.autoSyncInterval%",
"default": 180,
"minimum": 0
},
"fossil.autoRefresh": {
"type": "boolean",
Expand Down
5 changes: 2 additions & 3 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"command.commitStaged": "Commit Staged",
"command.commitAll": "Commit All",
"command.commitBranch": "Commit Creating New Branch...",
"command.sync": "Sync",
"command.undo": "Undo",
"command.update": "Update",
"command.redo": "Redo",
Expand All @@ -41,11 +42,9 @@
"command.merge": "Merge into working directory...",
"command.integrate": "Integrate into working directory...",
"command.cherrypick": "Cherry-pick into working directory...",
"config.enabled": "Whether Fossil is enabled",
"config.path": "Path to the 'fossil' executable (only required if auto-detection fails)",
"config.username": "The username associated with each commit (only required if different from user that originally cloned repo).",
"config.autoInOut": "Whether auto-incoming/outgoing counts are enabled",
"config.autoInOutInterval": "How many seconds between each autoInOut poll",
"config.autoSyncInterval": "The duration, in seconds, between each background `fossil sync` operation. 0 to disable.",
"config.autoRefresh": "Whether auto refreshing is enabled",
"config.enableRenaming": "Show rename request after a file was renamed in UI",
"config.enableLongCommitWarning": "Whether long commit messages should be warned about",
Expand Down
103 changes: 0 additions & 103 deletions src/autoinout.ts

This file was deleted.

12 changes: 9 additions & 3 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import * as humanise from './humanise';
import { partition } from './util';
import { toFossilUri } from './uri';
import { FossilPreviewManager } from './preview';
import type { FossilCWD, FossilExecutable, Reason } from './fossilExecutable';
import type { FossilCWD, FossilExecutable } from './fossilExecutable';

import { localize } from './main';
import type { Credentials } from './gitExport';
Expand Down Expand Up @@ -109,6 +109,7 @@ type CommandKey =
| 'stashPop'
| 'stashSave'
| 'stashSnapshot'
| 'sync'
| 'undo'
| 'unstage'
| 'unstageAll'
Expand Down Expand Up @@ -196,7 +197,7 @@ export class CommandCenter {

@command(Inline.Repository)
async refresh(repository: Repository): Promise<void> {
await repository.status('forced refresh' as Reason);
await repository.refresh();
}

@command()
Expand Down Expand Up @@ -1118,7 +1119,7 @@ export class CommandCenter {

const checkin = await interaction.pickUpdateCheckin(refs);
if (checkin) {
repository.update(checkin);
await repository.update(checkin);
}
}

Expand Down Expand Up @@ -1404,6 +1405,11 @@ export class CommandCenter {
}
}

@command(Inline.Repository)
async sync(repository: Repository): Promise<void> {
await repository.sync();
}

@command()
async praise(): Promise<void> {
const editor = window.activeTextEditor;
Expand Down
10 changes: 6 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { workspace } from 'vscode';
import type { FossilUsername } from './openedRepository';
import type { FossilUsername, Distinct } from './openedRepository';
import type { UnvalidatedFossilExecutablePath } from './fossilFinder';

export type AutoSyncIntervalMs = Distinct<number, 'AutoSyncIntervalMs'>;

interface ConfigScheme {
ignoreMissingFossilWarning: boolean;
path: UnvalidatedFossilExecutablePath;
autoInOutInterval: number;
autoSyncInterval: number;
username: FossilUsername; // must be ignored when empty
autoRefresh: boolean;
enableRenaming: boolean;
Expand Down Expand Up @@ -37,8 +39,8 @@ class Config {
return this.get('autoRefresh');
}

get autoInOutIntervalMs(): number {
return this.get('autoInOutInterval') * 1000;
get autoSyncIntervalMs(): AutoSyncIntervalMs {
return (this.get('autoSyncInterval') * 1000) as AutoSyncIntervalMs;
}

get enableRenaming(): boolean {
Expand Down
14 changes: 11 additions & 3 deletions src/fossilExecutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ export type FossilExecutablePath = Distinct<string, 'fossil executable path'>;

export interface FossilSpawnOptions extends cp.SpawnOptionsWithoutStdio {
readonly cwd: FossilCWD;
readonly logErrors?: boolean; // whether to log stderr to the fossil outputChannel
readonly stdin_data?: string; // dump data to stdin
/**
* Whether to log stderr to the fossil outputChannel and
* whether to show message box with an error
*/
readonly logErrors?: boolean;
/** Supply data to stdin */
readonly stdin_data?: string;
}

interface FossilRawResult {
Expand Down Expand Up @@ -106,6 +111,7 @@ type FossilCommand =
| 'sqlite'
| 'stash'
| 'status'
| 'sync'
| 'tag'
| 'test-markdown-render'
| 'test-wiki-render'
Expand Down Expand Up @@ -367,7 +373,9 @@ export class FossilExecutable {
})();

if (options.logErrors !== false && result.stderr) {
this.outputChannel.error(result.stderr);
this.outputChannel.error(
`(${args.join(', ')}): ${result.stderr}`
);
}
const failure: ExecFailure = {
...result,
Expand Down
11 changes: 8 additions & 3 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ export class Model implements Disposable {
this.foundExecutable.bind(this)
);
}
if (!event || event.affectsConfiguration('fossil.autoSyncInterval')) {
for (const repository of this.repositories) {
repository.updateAutoSyncInterval(
typedConfig.autoSyncIntervalMs
);
}
}
}

public async foundExecutable(
Expand Down Expand Up @@ -343,9 +350,7 @@ export class Model implements Disposable {
for (const { oldUri, newUri } of e.files) {
const repository = this.getRepository(oldUri);
if (repository) {
await repository.updateModelState(
'file rename event' as Reason
);
await repository.updateStatus('file rename event' as Reason);
if (
repository.isInAnyGroup(oldUri) ||
repository.isDirInAnyGroup(oldUri)
Expand Down
16 changes: 14 additions & 2 deletions src/openedRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,20 @@ export class OpenedRepository {
return (result.stdout + result.stderr).trim();
}

async update(checkin?: FossilCheckin): Promise<void> {
await this.exec(['update', ...(checkin ? [checkin] : [])]);
async update(
checkin?: FossilCheckin,
dryRun?: true,
reason?: Reason
): Promise<ExecResult> {
return this.exec(
[
'update',
...(checkin ? [checkin] : []),
...(dryRun ? ['--dry-run', '--latest'] : []),
],
reason,
{ logErrors: !dryRun }
);
}

async commit(
Expand Down
Loading