Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
git.listFiles({dir: projectPath}).then((files) => {
console.log("git files:", files);
if (!files || files.length === 0) {// no repo here
init(projectPath).then(resolve).catch(reject);
} else {
resolve(files);
}
});
})
}
export async function getGitTrackingStatus(
projectRoot: string
): Promise {
// buffer
const untracked = []
const tracked = []
const gitFiles: string[] = await git.listFiles({ fs, dir: projectRoot })
const gitFilepathIndexed: { [s: string]: boolean } = gitFiles.reduce(
(acc: { [s: string]: boolean }, pathname: string) => {
const relpath = pathname.replace(projectRoot, "")
return { ...acc, [relpath]: true }
},
{}
)
const allFiles = await getFilesRecursively(projectRoot)
const relativeFilepaths = allFiles.map(pathname =>
pathname.replace(projectRoot + "/", "")
)
for (const relpath of relativeFilepaths) {
if (gitFilepathIndexed[relpath]) {
tracked.push(relpath)
async function deleteAllFilesInLocalRepo(dir) {
const filePaths = await listFiles({ fs: oldFs, dir });
const fullFilePaths = filePaths.map(path => join(dir, path));
await deletePaths(fullFilePaths);
}
export async function listGitFiles(
projectRoot: string,
ref: string = "HEAD"
): Promise<
Array<{
filepath: string
gitStatus: string
}>
> {
const files: string[] = await git.listFiles({
dir: projectRoot,
ref
})
const statusList = await Promise.all(
files.map(f => getFileStatus(projectRoot, f))
)
return zipWith(files, statusList, (filepath, gitStatus) => ({
filepath,
gitStatus
}))
}
async function deleteAllFilesInLocalRepo(dir) {
const filePaths = await listFiles({ fs: oldFs, dir });
const fullFilePaths = filePaths.map(path => join(dir, path));
await deletePaths(fullFilePaths);
}
export async function getUntrackingFiles(
projectRoot: string
): Promise {
const tracked: string[] = await git.listFiles({
dir: projectRoot,
ref: "HEAD"
})
const files = (await getFilesRecursively(projectRoot)).map(pathname =>
pathname.replace(projectRoot + "/", "")
)
return difference(files, tracked)
}
export async function getTrackingStatus(
projectRoot: string
): Promise {
const trackedByHead: string[] = await git.listFiles({
dir: projectRoot,
ref: "HEAD"
})
const trackedByIndex: string[] = await git.listFiles({
dir: projectRoot
})
const tracked = uniq([...trackedByHead, ...trackedByIndex])
const files = (await getFilesRecursively(projectRoot)).map(pathname =>
pathname.replace(projectRoot + "/", "")
)
const untracked = difference(files, tracked)
return {
tracked,
untracked
}
}
export async function listGitFilesInRepository(
projectRoot: string
): Promise<
Array<{
filepath: string
gitStatus: string
}>
> {
const files: string[] = await git.listFiles({ fs, dir: projectRoot })
const statusList = await Promise.all(
files.map(f => getGitStatusInRepository(projectRoot, f))
)
return zipWith(files, statusList, (filepath, gitStatus) => ({
filepath,
gitStatus
}))
}