/**
* 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;
}