Populate resource groups for unrecorded and untracked changes

[?]
Dec 24, 2020, 3:23 AM
YUVLBWV3UDNQG63DMTQQOBBL4WMK2J7ODPIZ5337X5PDBZYFQO6AC

Dependencies

  • [2] IBRKAWNM Moved utility modules into their own folder
  • [3] B4SKYP3Y Add repository model and add steps to initialize it
  • [4] ZGMIJNFV Create pijul.ts for executing commands using the Pijul CLI

Change contents

  • edit in src/repository.ts at line 34
    [3.1512]
    [3.1512]
    this.refreshStatus();
  • edit in src/repository.ts at line 39
    [3.1523]
    [3.1523]
    * Refresh the repository status by recalculating the state of all the files
    * in the workspace and updating the resource groups.
    *
    * TODO: Refresh automatically when files in the workspace change
    */
    async refreshStatus (): Promise<void> {
    this.outputChannel.appendLine('Refreshing Pijul Status...');
    this.untrackedGroup.resourceStates = (await this.repository.getUntrackedFiles()).map(u => ({ resourceUri: u }));
    this.unrecordedChangesGroup.resourceStates = (await this.repository.getChangedFiles()).map(u => ({ resourceUri: u }));
    this.outputChannel.appendLine('Pijul Status Refreshed');
    }
    /**
  • replacement in src/pijul.ts at line 4
    [4.129][4.129:173]()
    import { CancellationToken } from 'vscode';
    [4.129]
    [2.0]
    import * as path from 'path';
    import { CancellationToken, TextDocument, Uri, workspace } from 'vscode';
  • edit in src/pijul.ts at line 8
    [2.126]
    [4.287]
    import { createResourceUri } from './utils/fileUtils';
  • edit in src/pijul.ts at line 148
    [4.4613]
    [4.4613]
    }
    /**
    * Get the files in the Repository which Pijul is aware of, the results of `pijul ls`
    */
    async getTrackedFiles (): Promise<Uri[]> {
    return (await this.pijul.exec(this.repositoryRoot, ['ls'])).stdout.split('\n').map(f => createResourceUri(f));
  • edit in src/pijul.ts at line 156
    [4.4617]
    [4.4617]
    /**
    * Get all the files in the repository, including those which haven't been added to Pijul
    */
    async getNotIgnoredFiles (): Promise<Uri[]> {
    // TODO: More robust handling of ignore files
    let ignoreFile: TextDocument | undefined;
    try {
    ignoreFile = await workspace.openTextDocument(path.join(this.repositoryRoot, '.ignore'));
    } catch (err) {
    try {
    ignoreFile = await workspace.openTextDocument(path.join(this.repositoryRoot, '.pijulignore'));
    } catch (err) {
    // No ignore file exists, continue
    }
    }
    const ignoreGlobs: string[] = [];
    if (ignoreFile) {
    for (let i = 0; i < ignoreFile.lineCount; i++) {
    const line = ignoreFile.lineAt(i).text;
    if (!line.startsWith('#')) {
    ignoreGlobs.push(line);
    }
    }
    }
    // Make sure files in the .pijul folder aren't being tracked
    ignoreGlobs.push('**/.pijul/**');
    const fullIgnoreGlob = '{' + ignoreGlobs.join(',') + '}';
    return await workspace.findFiles('**', fullIgnoreGlob);
    }
    /**
    * Calculate the difference between the tracked files and the full set of files in the repository
    * to determine which of the files are untracked.
    *
    * TODO: Maybe consider adding this functionality to Pijul?
    */
    async getUntrackedFiles (): Promise<Uri[]> {
    // TODO: Easy optimization here
    const trackedFiles = await this.getTrackedFiles();
    const allFiles = await this.getNotIgnoredFiles();
    return allFiles.filter(f => !trackedFiles.some(t => t.path === f.path));
    }
    /**
    * Get the list of file URIs which have unrecorded changes
    */
    async getChangedFiles (): Promise<Uri[]> {
    const pijulDiff = JSON.parse((await this.pijul.exec(this.repositoryRoot, ['diff', '--json'])).stdout);
    const changedFiles: Uri[] = [];
    for (const file in pijulDiff) {
    changedFiles.push(createResourceUri(file));
    }
    return changedFiles;
    }