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

Maintenance May 2024 #185

Merged
merged 20 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,21 @@ about cloning from the extension.

# Settings

`fossil.enabled { boolean }`

* Enables Fossil as a source control manager in VS Code.

`fossil.autoRefresh { boolean }`

* Enables automatic refreshing of Source Control tab and badge counter
when files within the project change:
`"true"` — enabled
`"false"` — disabled, manual refresh still available.

`fossil.path { string / null }`
`fossil.path { string }`

* 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` in commonly-known
install locations and on the PATH.
* The default behaviour is to search for `fossil` on the PATH.
* Takes effect immediately.

`fossil.username { string / null }`
`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.
Expand Down
138 changes: 71 additions & 67 deletions package.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {
Disposable,
window,
workspace,
OutputChannel,
SourceControlResourceState,
SourceControlResourceGroup,
TextDocumentShowOptions,
ViewColumn,
Selection,
ExtensionContext,
SourceControl,
LogOutputChannel,
} from 'vscode';
import { LineChange, revertChanges } from './revert';
import * as path from 'path';
Expand Down Expand Up @@ -48,7 +48,7 @@ import * as humanise from './humanise';
import { partition } from './util';
import { toFossilUri } from './uri';
import { FossilPreviewManager } from './preview';
import { FossilExecutable, FossilCWD } from './fossilExecutable';
import type { FossilCWD, FossilExecutable } from './fossilExecutable';

import { localize } from './main';
import type { Credentials } from './gitExport';
Expand Down Expand Up @@ -182,7 +182,7 @@ export class CommandCenter {
constructor(
private readonly executable: FossilExecutable,
private readonly model: Model,
private readonly outputChannel: OutputChannel,
private readonly outputChannel: LogOutputChannel,
context: ExtensionContext
) {
this.previewManager = new FossilPreviewManager(context, executable);
Expand Down Expand Up @@ -731,7 +731,7 @@ export class CommandCenter {
scmResources,
s => s.status !== ResourceStatus.ADDED
);
if (discardResources.length > 0) {
if (discardResources.length) {
const confirmFilenames = discardResources.map(r =>
path.basename(r.resourceUri.fsPath)
);
Expand Down Expand Up @@ -1398,7 +1398,7 @@ export class CommandCenter {
}
}
} else {
this.outputChannel.appendLine(
this.outputChannel.error(
"couldn't create wiki entity - no active preview"
);
}
Expand Down
41 changes: 19 additions & 22 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { workspace } from 'vscode';
import { FossilUsername } from './openedRepository';
import { UnvalidatedFossilExecutablePath } from './fossilFinder';
import type { FossilUsername } from './openedRepository';
import type { UnvalidatedFossilExecutablePath } from './fossilFinder';

interface ConfigScheme {
enabled: boolean;
path: UnvalidatedFossilExecutablePath | null;
ignoreMissingFossilWarning: boolean;
path: UnvalidatedFossilExecutablePath;
autoInOutInterval: number;
username: FossilUsername | null;
username: FossilUsername; // must be ignored when empty
autoRefresh: boolean;
enableRenaming: boolean;
confirmGitExport: 'Automatically' | 'Never' | null;
Expand All @@ -22,22 +22,11 @@ class Config {
): ConfigScheme[TName] {
// for keys existing in packages.json this function
// will not return `undefined`
return this.config.get<ConfigScheme[TName]>(
name
) as ConfigScheme[TName];
return this.config.get<ConfigScheme[TName]>(name)!;
}

/**
* This flag should be removed. It exists because there's no way to
* disable `git` internal extension in vscode using extensions UI
* and this code is a fork of internal extension.
*/
get enabled(): boolean {
return this.get('enabled');
}

get path(): UnvalidatedFossilExecutablePath | null {
return this.get('path');
get path(): UnvalidatedFossilExecutablePath {
return this.get('path').trim() as UnvalidatedFossilExecutablePath;
}

/**
Expand All @@ -56,21 +45,29 @@ class Config {
return this.get('enableRenaming');
}

get ignoreMissingFossilWarning(): boolean {
return this.get('ignoreMissingFossilWarning');
}

disableMissingFossilWarning() {
return this.config.update('ignoreMissingFossilWarning', true, false);
}

/**
* * Specifies an explicit user to use for fossil commits.
* * This should only be used if the user is different
* than the fossil default user.
*/
get username(): FossilUsername | null {
get username(): FossilUsername {
return this.get('username');
}

disableRenaming() {
this.config.update('enableRenaming', false, false);
return this.config.update('enableRenaming', false, false);
}

setGitExport(how: NonNullable<ConfigScheme['confirmGitExport']>) {
this.config.update('confirmGitExport', how, false);
return this.config.update('confirmGitExport', how, false);
}

get gitExport() {
Expand Down
42 changes: 12 additions & 30 deletions src/fossilExecutable.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import {
import type {
Distinct,
FossilPath,
FossilRoot,
FossilURI,
} from './openedRepository';
import * as path from 'path';
import * as fs from 'fs/promises';
import {
EventEmitter,
Event,
window,
OutputChannel,
ProgressLocation,
} from 'vscode';
import { window, LogOutputChannel, ProgressLocation } from 'vscode';
import * as cp from 'child_process';
import { dispose, IDisposable, toDisposable } from './util';
import * as interaction from './interaction';
import type { FossilExecutableInfo } from './fossilFinder';

/** usually two numbers like [2,19] */
export type FossilVersion = Distinct<number[], 'fossil version'>;
Expand All @@ -25,12 +20,6 @@ export type FossilStdOut = Distinct<
>;
export type FossilStdErr = Distinct<string, 'raw fossil stderr'>;

export interface IFossilOptions {
readonly fossilPath: FossilExecutablePath;
readonly version: FossilVersion;
readonly outputChannel: OutputChannel;
}

/** cwd for executing fossil */
export type FossilCWD =
| Distinct<string, 'cwd for executing fossil'>
Expand Down Expand Up @@ -138,18 +127,13 @@ export function toString(this: ExecFailure): string {
}

export class FossilExecutable {
private readonly fossilPath: FossilExecutablePath;
private readonly outputChannel: OutputChannel;
public readonly version: FossilVersion;
private readonly _onOutput = new EventEmitter<string>();
get onOutput(): Event<string> {
return this._onOutput.event;
}
private fossilPath!: FossilExecutablePath;
public version!: FossilVersion;
constructor(public readonly outputChannel: LogOutputChannel) {}

constructor(options: IFossilOptions) {
this.fossilPath = options.fossilPath;
this.outputChannel = options.outputChannel;
this.version = options.version;
setInfo(info: FossilExecutableInfo) {
this.fossilPath = info.path;
this.version = info.version;
}

async init(
Expand Down Expand Up @@ -378,7 +362,7 @@ export class FossilExecutable {
})();

if (options.logErrors !== false && result.stderr) {
this.log(`${result.stderr}\n`);
this.outputChannel.error(result.stderr);
}
const failure: ExecFailure = {
...result,
Expand All @@ -402,7 +386,7 @@ export class FossilExecutable {
}

private log(output: string): void {
this._onOutput.fire(output);
this.outputChannel.info(output);
}
private logArgs(args: FossilArgs, reason: string, info: string): void {
if (args[0] == 'clone') {
Expand All @@ -411,9 +395,7 @@ export class FossilExecutable {
args[1] = args[1].replace(/(.*:\/\/.+:)(.+)(@.*)/, '$1*********$3');
}
this.log(
`fossil ${args.join(' ')}: ${info}${
reason ? ' // ' + reason : ''
}\n`
`fossil ${args.join(' ')}: ${info}${reason ? ' // ' + reason : ''}`
);
}
}
Expand Down
Loading