Populate resource groups for unrecorded and untracked changes
[?]
Dec 24, 2020, 3:23 AM
YUVLBWV3UDNQG63DMTQQOBBL4WMK2J7ODPIZ5337X5PDBZYFQO6ACDependencies
- [2]
IBRKAWNMMoved utility modules into their own folder - [3]
B4SKYP3YAdd repository model and add steps to initialize it - [4]
ZGMIJNFVCreate pijul.ts for executing commands using the Pijul CLI
Change contents
- edit in src/repository.ts at line 34
this.refreshStatus(); - edit in src/repository.ts at line 39
* 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
import { CancellationToken } from 'vscode';import * as path from 'path';import { CancellationToken, TextDocument, Uri, workspace } from 'vscode'; - edit in src/pijul.ts at line 8
import { createResourceUri } from './utils/fileUtils'; - edit in src/pijul.ts at line 148
}/*** 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
/*** 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 fileslet 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 trackedignoreGlobs.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 hereconst 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;}