Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
await pify(fs.mkdir)("/repo")
} catch (e) {
// repo exists
}
// ensure git
if (await existsPath(j(projectRoot, ".git"))) {
// Pass
} else {
await git.init({ dir: projectRoot })
await git.add({
dir: "/playground",
filepath: "README.md"
})
await git.add({
dir: "/playground",
filepath: ".gitignore"
})
await git.add({
dir: "/playground",
filepath: "scratch.md"
})
await git.commit({
author: {
email: "dummy",
name: "system"
},
dir: "/playground",
message: "Init"
})
}
export async function commitAll(
root: string,
message: string,
author: { name: string; email: string }
): Promise {
const mat = await git.statusMatrix({ dir: root })
const modified = Parser.getModifiedFilenames(mat)
const removable = Parser.getRemovableFilenames(mat)
for (const filepath of modified) {
if (removable.includes(filepath)) {
await git.remove({ dir: root, filepath })
} else {
// TODO: Why?????
if (filepath) {
await git.add({ dir: root, filepath })
}
}
}
return git.commit({
dir: root,
message,
author
})
}
dir: repoDir,
// Could use mz/fs but I don't trust it guarentees compatibility with isomorphic git
fs: oldFs,
url: gitInfo.repoUrl,
singleBranch: true,
depth: 1,
...gitInfo.auth,
});
await migrateSdkIntoLocalRepo(repoDir, remoteSdkUrl, options);
const addedPaths = await getAllStageableFilepathsInRepo(repoDir);
logger.verbose(`Staging ${addedPaths.length} paths`);
for (const addedPath of addedPaths) {
const relativeFilePath = relative(repoDir, addedPath);
// TODO: Got a lot of "oldFs: fs", maybe make some sort of wrapper to avoid this?
await add({
fs: oldFs,
dir: repoDir,
filepath: relativeFilePath,
});
}
logger.verbose(`Committing changes...`);
await commit({
fs: oldFs,
dir: repoDir,
// TODO: This should be configurable
author: {
name: 'Swagger Platform',
email: 'N/A',
},
// TODO: Could have a better message
message: 'Updated SDK',
export async function batchUpdateFiles(
projectRoot: string,
files: Array<[string, string]>,
message: string = "Update"
): Promise {
for (const [filename, content] of files) {
await fs.promises.writeFile(path.join(projectRoot, filename), content)
await git.add({ dir: projectRoot, filepath: filename })
}
return git.commit({
dir: projectRoot,
message,
author: { name: "test", email: "test" }
})
}
export const gitCommit = async (message: string) => {
const paths = await globby(['./**', './**/.*'], {gitignore: true});
for (const filepath of paths) {
await git.add({fs, dir: '.', filepath}).catch(() => {});
}
const {user = {name: 'dubstep', email: 'dubstep'}} = await getGlobalConfig();
const name = (await get('user.name')) || user.name;
const email = (await get('user.email')) || user.email;
await git.commit({fs, dir: '.', author: {name, email}, message});
};
export async function createProject(newProjectRoot: string): Promise {
await mkdir(newProjectRoot)
await git.init({ dir: newProjectRoot })
const outpath = path.join(newProjectRoot, "README.md")
await writeFile(outpath, "# New Project")
await git.add({ dir: newProjectRoot, filepath: "README.md" })
await git.commit({
dir: newProjectRoot,
author: { name: "system", email: "dummy" },
message: "Init"
})
}
actions.gitAddFailed({
error: new Error("no notebook loaded to add"),
contentRef: action.payload.contentRef
})
);
}
const filepath = content.filepath;
const repo = {
fs,
dir: filepath.substring(0, filepath.lastIndexOf("/"))
};
const notebookdir = filepath.split("/");
const notebook = notebookdir[notebookdir.length - 1];
const notificationSystem = selectors.notificationSystem(state);
return from(git.add({ ...repo, filepath: notebook })).pipe(
map(
() =>
actions.gitAddSuccessful({ contentRef: action.payload.contentRef }),
notificationSystem.addNotification({
title: "Changes Staged",
message: `Changes to the notebook have been staged.`,
dismissible: true,
position: "tr",
level: "success"
})
),
catchError(err => {
actions.gitAddFailed(err);
})
);
})
export function addFile(projectRoot: string, relpath: string): Promise {
return git.add({ dir: projectRoot, filepath: relpath })
}
private async _add(path: string) {
this._index.push(path);
await add({
dir: this.projectDir,
filepath: path
});
}
}
export function addFileInRepository(
projectRoot: string,
relpath: string
): Promise {
return git.add({ fs, dir: projectRoot, filepath: relpath })
}