From a64fa752460f45bfb566411d0d62dc5660b00e5b Mon Sep 17 00:00:00 2001 From: Josh Heng Date: Sun, 4 Aug 2024 23:30:45 +0100 Subject: [PATCH 1/2] feat: Add follow option --- README.md | 6 ++++++ src/index.ts | 11 +++++++++++ test/gitlog.test.ts | 17 +++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/README.md b/README.md index 895e9d8..27fddb9 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 () => { From 9136323066652fbf550b4d4f7b8dad4b1cc31428 Mon Sep 17 00:00:00 2001 From: Dom Harrington Date: Mon, 5 Aug 2024 11:16:47 +0100 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 27fddb9..ee69cd6 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ This option is disabled by default. ### follow -Pass the -follow option to follow files across renames. +Pass the --follow option to follow files across renames. This option is disabled by default.