mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 23:00:30 +00:00
30 lines
925 B
TypeScript
30 lines
925 B
TypeScript
import { GitVCS } from './git-vcs';
|
|
|
|
export interface FileWithStatus {
|
|
filePath: string;
|
|
status: string;
|
|
}
|
|
|
|
const isAdded = ({ status }: FileWithStatus) => status.includes('added');
|
|
|
|
const isNotAdded = ({ status }: FileWithStatus) => !status.includes('added');
|
|
|
|
export const gitRollback = async (vcs: GitVCS, files: FileWithStatus[]) => {
|
|
const addedFiles = files.filter(isAdded);
|
|
// Remove and delete added (unversioned) files
|
|
const promises = addedFiles.map(async ({ filePath }) => {
|
|
await vcs.remove(filePath);
|
|
console.log(`[git-rollback] Delete relPath=${filePath}`);
|
|
// @ts-expect-error -- TSCONVERSION
|
|
await vcs.getFs().promises.unlink(filePath);
|
|
});
|
|
// Rollback existing (versioned) files
|
|
const existingFiles = files.filter(isNotAdded).map(f => f.filePath);
|
|
|
|
if (existingFiles.length) {
|
|
promises.push(vcs.undoPendingChanges(existingFiles));
|
|
}
|
|
|
|
await Promise.all(promises);
|
|
};
|