diff --git a/README.md b/README.md index 895e9d8..ee69cd6 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,12 @@ Pass the `-m` option to includes files in a merge commit. This option is disabled by default. +### follow + +Pass the --follow option to follow files across renames. + +This option is disabled by default. + ### all Find commits on all branches instead of just on the current one. diff --git a/src/index.ts b/src/index.ts index 5db5630..0e8fc25 100644 --- a/src/index.ts +++ b/src/index.ts @@ -80,6 +80,12 @@ export interface GitlogOptions { * @default false */ includeMergeCommitFiles?: boolean; + /** + * Pass the -follow option to follow files across renames + * + * @default false + */ + follow?: boolean; /** * The number of commits to return * @@ -128,6 +134,7 @@ const defaultOptions = { fields: defaultFields, nameStatus: true, includeMergeCommitFiles: false, + follow: false, findCopiesHarder: false, all: false, }; @@ -258,6 +265,10 @@ function createCommandArguments< command.push("-m"); } + if (options.follow) { + command.push("--follow"); + } + command.push(`-n ${options.number}`); command = addOptionalArguments(command, options); diff --git a/test/gitlog.test.ts b/test/gitlog.test.ts index e89d19a..0f39618 100644 --- a/test/gitlog.test.ts +++ b/test/gitlog.test.ts @@ -249,6 +249,23 @@ describe("gitlog", () => { expect(commits[3].files[0]).toBe("foo"); }); + it("doesn't return commits for renamed files when follow is false or undefined", async () => { + const commits = await gitlog({ + repo: testRepoLocation, + file: "1-fileRename", + }); + expect(commits.length).toBe(2); + }); + + it("returns commits for renamed files when follow is true", async () => { + const commits = await gitlog({ + repo: testRepoLocation, + file: "1-fileRename", + follow: true, + }); + expect(commits.length).toBe(3); + }); + describe("Only repo option", () => { let commits: any[]; beforeAll(async () => {