diff --git a/src/plugins/git/cloneAndLoadRepository.js b/src/plugins/git/cloneAndLoadRepository.js index 6e07f4c..8355681 100644 --- a/src/plugins/git/cloneAndLoadRepository.js +++ b/src/plugins/git/cloneAndLoadRepository.js @@ -7,7 +7,8 @@ import {loadRepository} from "./loadRepository"; import type {Repo} from "../../core/repo"; /** - * Load Git Repository data from a fresh clone of a GitHub repo. + * Load Git repository data from a fresh clone of a GitHub repo. Loads + * commits only. * * @param {Repo} repo * the GitHub repository to be cloned @@ -19,7 +20,7 @@ export default function cloneAndLoadRepository(repo: Repo): Repository { const tmpdir = tmp.dirSync({unsafeCleanup: true}); const git = localGit(tmpdir.name); git(["clone", cloneUrl, ".", "--quiet"]); - const result = loadRepository(tmpdir.name, "HEAD"); + const result = loadRepository(tmpdir.name, "HEAD", "COMMITS_ONLY"); tmpdir.removeCallback(); return result; } diff --git a/src/plugins/git/loadRepository.js b/src/plugins/git/loadRepository.js index b62d211..fdc0b67 100644 --- a/src/plugins/git/loadRepository.js +++ b/src/plugins/git/loadRepository.js @@ -21,11 +21,21 @@ import {localGit} from "./gitUtils"; */ export function loadRepository( repositoryPath: string, - rootRef: string + rootRef: string, + mode: "FULL" | "COMMITS_ONLY" = "FULL" ): Repository { const git = localGit(repositoryPath); const commits = findCommits(git, rootRef); - const trees = findTrees(git, new Set(commits.map((x) => x.treeHash))); + const trees = (() => { + switch (mode) { + case "FULL": + return findTrees(git, new Set(commits.map((x) => x.treeHash))); + case "COMMITS_ONLY": + return []; + default: + throw new Error((mode: empty)); + } + })(); return {commits: objectMap(commits), trees: objectMap(trees)}; } diff --git a/src/plugins/git/loadRepository.test.js b/src/plugins/git/loadRepository.test.js index 5e03870..2f49412 100644 --- a/src/plugins/git/loadRepository.test.js +++ b/src/plugins/git/loadRepository.test.js @@ -29,6 +29,16 @@ describe("loadRepository", () => { ); }); + it("respects commits-only mode", () => { + const repository = createExampleRepo(mkdtemp()); + const full = loadRepository(repository.path, "HEAD"); + const commitsOnly = loadRepository(repository.path, "HEAD", "COMMITS_ONLY"); + expect(commitsOnly).toEqual({ + commits: full.commits, + trees: {}, + }); + }); + it("processes an old commit", () => { const repository = createExampleRepo(mkdtemp()); const whole = loadRepository(repository.path, "HEAD");