Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function getFileHistory(
dir: string,
ref: string,
filepath: string
): Promise<
Array<{
commit: CommitDescription
blob: GitBlobDescription
}>
> {
const commits: CommitDescription[] = await git.log({ dir, ref })
const rawChanges = await Promise.all(
commits.map(async commit => {
try {
const blob = await git.readObject({
dir,
oid: commit.oid,
filepath
})
return {
commit,
blob
}
} catch (e) {
return
}
})
export async function getHistory(
projectRoot: string,
{ depth, ref = "master" }: { depth?: number; ref?: string }
): Promise {
return git.log({ dir: projectRoot, depth, ref })
}
export async function isFastForward(
dir: string,
refA: string,
refB: string
): Promise<
| {
fastForward: false
}
| {
fastForward: true
self: boolean
commits: CommitDescription[]
}
> {
const logA: CommitDescription[] = await git.log({ dir, ref: refA })
const logB: CommitDescription[] = await git.log({ dir, ref: refB })
const fastForward: boolean = isFastForwardByCommits(logA, logB)
if (fastForward) {
const oid = logA[logA.length - 1].oid
const index = logB.findIndex(i => i.oid === oid)
return {
fastForward: true,
self: logA[0].oid === logB[0].oid,
commits: logB.slice(index)
}
} else {
return {
fastForward: false
}
}
}
gitLog(msg){
if( !msg ) msg = {depth:10};
log("------ GIT LOG ------");
log("(Newest entries last)");
git.log(Object.assign({dir}, msg))
.then(list=>{
list.reverse()
.forEach(entry=>{
log(entry.message);
});
});
}
export async function getLogInRepository(
projectRoot: string,
{ depth, ref = "master" }: { depth?: number; ref?: string }
): Promise {
return git.log({ fs, dir: projectRoot, depth, ref })
}
async commitLog(): Promise {
return await log({
dir: this.projectDir
});
}