Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async getContainerRepository(repositoryPath: string): Promise {
// Do not log an error if we are not contained in a Git repository. Treat exit code 128 as a success too.
const options = { successExitCodes: new Set([0, 128]) };
const result = await git(['rev-parse', '--show-toplevel'], repositoryPath, 'rev-parse', options);
const out = result.stdout;
if (out && out.length !== 0) {
const localUri = FileUri.create(out.trim()).toString();
return { localUri };
}
return undefined;
}
it('modifying a staged file should result in two changes', async () => {
// Init repository.
const root = await createTestRepository(track.mkdirSync('status-test'));
const localUri = FileUri.create(root).toString();
const repository = { localUri };
const git = await createGit();
// // Check status. Expect empty.
let status = await git.status(repository);
expect(status.changes).to.be.empty;
// Modify a file.
const filePath = path.join(root, 'A.txt');
const fileUri = FileUri.create(filePath).toString();
fs.writeFileSync(filePath, 'new content');
expect(fs.readFileSync(filePath, { encoding: 'utf8' })).to.be.equal('new content');
await git.add(repository, fileUri);
// Check the status again. Expect one single change.
status = await git.status(repository);
expect(status.changes).to.be.have.lengthOf(1);
expect(status.changes[0].uri).to.be.equal(fileUri);
expect(status.changes[0].staged).to.be.true;
// Change the same file again.
fs.writeFileSync(filePath, 'yet another new content');
expect(fs.readFileSync(filePath, { encoding: 'utf8' })).to.be.equal('yet another new content');
// We expect two changes; one is staged, the other is in the working directory.
status = await git.status(repository);
function compareSearchResults(expected: SearchInWorkspaceResult[], actual: SearchInWorkspaceResult[]): void {
expect(actual.length).eq(expected.length);
if (actual.length !== expected.length) {
return;
}
for (let i = 0; i < actual.length; i++) {
const e = expected[i];
const lines = fileLines.get(e.fileUri);
if (lines) {
const line = lines[e.line - 1];
e.lineText = line;
e.fileUri = FileUri.create(path.join(getRootPathFromName(e.fileUri), e.fileUri)).toString();
const a = actual.find(l => l.fileUri === e.fileUri && l.line === e.line && l.character === e.character);
expect(a).deep.eq(e);
} else {
// We don't know this file...
expect.fail();
}
}
}
before(() => {
chai.should();
chai.use(chaiAsPromised);
chai.config.showDiff = true;
chai.config.includeStack = true;
const rootUri = FileUri.create(track.mkdirSync());
preferenceFileUri = rootUri.resolve(preferencePath);
prefServer = helper.createJsonPrefServer(preferenceFileUri);
fs.mkdirSync(FileUri.fsPath(rootUri.resolve('.theia')));
fs.writeFileSync(FileUri.fsPath(preferenceFileUri), '{ "showLineNumbers": false }');
});
protected getUri(request: Request): MaybePromise {
const decodedPath = request.path.substr(MiniBrowserEndpoint.HANDLE_PATH.length);
return new URI(FileUri.create(decodedPath).toString(true)).toString(true);
}
private getUri(path: string): string {
return FileUri.create(path).toString();
}
before(() => {
rootDirA = track.mkdirSync();
rootDirB = track.mkdirSync();
rootSubdirA = track.mkdirSync({ dir: rootDirA });
rootDirAUri = FileUri.create(rootDirA).toString();
rootDirBUri = FileUri.create(rootDirB).toString();
rootSubdirAUri = FileUri.create(rootSubdirA).toString();
createTestFile('carrots', `\
This is a carrot.
Most carrots are orange, but some carrots are not.
Once capitalized, the word carrot looks like this: CARROT.
Carrot is a funny word.
`);
createTestFile('potatoes', `\
Potatoes, unlike carrots, are generally not orange. But sweet potatoes are,
it's very confusing.
`);
createTestFile('pastas', 'pasta pasta');
createTestFile('regexes', `\
before(() => {
rootDirA = track.mkdirSync();
rootDirB = track.mkdirSync();
rootSubdirA = track.mkdirSync({ dir: rootDirA });
rootDirAUri = FileUri.create(rootDirA).toString();
rootDirBUri = FileUri.create(rootDirB).toString();
rootSubdirAUri = FileUri.create(rootSubdirA).toString();
createTestFile('carrots', `\
This is a carrot.
Most carrots are orange, but some carrots are not.
Once capitalized, the word carrot looks like this: CARROT.
Carrot is a funny word.
`);
createTestFile('potatoes', `\
Potatoes, unlike carrots, are generally not orange. But sweet potatoes are,
it's very confusing.
`);
createTestFile('pastas', 'pasta pasta');
protected readThemes(pck: PluginPackage): ThemeContribution[] | undefined {
if (!pck.contributes || !pck.contributes.themes) {
return undefined;
}
const result: ThemeContribution[] = [];
for (const contribution of pck.contributes.themes) {
if (contribution.path) {
result.push({
id: contribution.id,
uri: FileUri.create(path.join(pck.packagePath, contribution.path)).toString(),
description: contribution.description,
label: contribution.label,
uiTheme: contribution.uiTheme
});
}
}
return result;
}