mirror of
https://github.com/pomber/git-history.git
synced 2024-11-29 18:48:01 +03:00
48 lines
987 B
JavaScript
48 lines
987 B
JavaScript
const execa = require("execa");
|
|
|
|
// TODO remove
|
|
const options = { cwd: ".." };
|
|
|
|
async function getCommits(path) {
|
|
const format = `{"hash":"%h","author":{"login":"%aN"},"date":"%ad","message":"%f"},`;
|
|
const { stdout } = await execa(
|
|
"git",
|
|
[
|
|
"log",
|
|
"--follow",
|
|
"--reverse",
|
|
"--abbrev-commit",
|
|
`--pretty=format:${format}`,
|
|
"--date=iso",
|
|
"--",
|
|
path
|
|
],
|
|
options
|
|
);
|
|
const json = `[${stdout.slice(0, -1)}]`;
|
|
const result = JSON.parse(json).map(commit => ({
|
|
...commit,
|
|
date: new Date(commit.date)
|
|
}));
|
|
return result;
|
|
}
|
|
|
|
async function getContent(commit, path) {
|
|
const { stdout } = await execa(
|
|
"git",
|
|
["show", `${commit.hash}:${path}`],
|
|
options
|
|
);
|
|
return stdout;
|
|
}
|
|
|
|
module.exports = async function(path) {
|
|
const commits = await getCommits(path);
|
|
await Promise.all(
|
|
commits.map(async commit => {
|
|
commit.content = await getContent(commit, path);
|
|
})
|
|
);
|
|
return commits;
|
|
};
|