Add remotes view on the SCM panel

[?]
Jan 13, 2021, 6:37 PM
3FBABWSMIDOX2CITKFYHRBFW2EM3P37KPYDT44ACUP73MRJ5AXZQC

Dependencies

  • [2] 6S7IH4SQ Delay refresh event to avoid pristine locking issue
  • [3] VC2RHYTF Hide views on SCM panel when extension isn't activated
  • [4] TPJNM4C4 Show only the changes which are not in the current channel on the channel view
  • [*] L3VOQYAF Add changelog view to the source control panel
  • [*] B4SKYP3Y Add repository model and add steps to initialize it
  • [*] VT237HUJ Add tree view for channels
  • [*] ZGMIJNFV Create pijul.ts for executing commands using the Pijul CLI
  • [*] L44OILGK Add reset command to resource state context menu
  • [*] NCBEWRYE Initialize Repository

Change contents

  • file addition: remotes.ts (-xw-x--x--)
    [6.8]
    import { Event, TreeDataProvider, TreeItem, TreeItemCollapsibleState } from 'vscode';
    import { PijulRemote, Repository } from '../pijul';
    /**
    * The Changelog provider class is a Treedata provider which provides
    * TreeData for the `pijul.views.changelog` TreeView
    */
    export class RemotesViewProvider implements TreeDataProvider<PijulRemote> {
    /**
    * Create a new ChangelogViewProvider instance
    * @param repository
    */
    constructor (
    private readonly repository: Repository,
    public readonly onDidChangeTreeData?: Event<void>
    ) {}
    /**
    * Convert a PijulRemote into a TreeItem
    * @param element
    */
    getTreeItem (element: PijulRemote): TreeItem | Thenable<TreeItem> {
    return {
    label: element.url,
    collapsibleState: TreeItemCollapsibleState.None,
    contextValue: 'PijulRemote'
    };
    }
    /**
    * Get the children of the element or the root if no element is passed
    * @param element An optional element to get the children of
    */
    async getChildren (element?: PijulRemote): Promise<PijulRemote[] | null | undefined> {
    if (element) {
    // Remotes don't have children
    return null;
    } else {
    let children;
    // Retry if the pristine is locked. TODO: More robust solution
    while (!children) {
    try {
    children = await this.repository.getRemotes();
    } catch (err) {
    if (!(err instanceof Error) || !err.message.includes('Pristine locked')) {
    throw err;
    }
    }
    }
    return children;
    }
    }
    }
  • edit in src/repository.ts at line 10
    [8.1378]
    [7.229]
    import { RemotesViewProvider } from './views/remotes';
  • edit in src/repository.ts at line 112
    [2.305]
    [6.1450]
    this.disposables.push(window.registerTreeDataProvider('pijul.views.remotes', new RemotesViewProvider(this.repository, debounceEvent(this.onDidRefreshStatus, 200))));
  • edit in src/pijul.ts at line 470
    [4.959]
    [10.763]
    }
    /**
    * Get the remotes of this repository with `pijul remote`
    */
    async getRemotes (): Promise<PijulRemote[]> {
    return (await this._pijul.exec(this.repositoryRoot, ['remote'])).stdout.split(/\r?\n/).map(l => new PijulRemote(l.trim()));
  • edit in src/pijul.ts at line 637
    [8.2498]
    [8.2498]
    ) {}
    }
    /**
    * Class representing a remote repository
    */
    export class PijulRemote {
    /**
    * Create a new instance of a PijulRemote object
    * @param url The url of the remote
    */
    constructor (
    public readonly url: string
  • edit in package.json at line 499
    [3.171]
    [10.1681]
    },
    {
    "id": "pijul.views.remotes",
    "name": "Remotes",
    "contextualTitle": "Pijul",
    "visibility": "visible",
    "when": "config.pijul.enabled && pijul.activated"