Skip to content

Commit

Permalink
Merge pull request #102 from JoshHeng/feature/add-follow-parameter
Browse files Browse the repository at this point in the history
Add follow option
  • Loading branch information
domharrington authored Aug 5, 2024
2 parents 9253b53 + 9136323 commit 9a5273e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export interface GitlogOptions<Fields extends string = DefaultField> {
* @default false
*/
includeMergeCommitFiles?: boolean;
/**
* Pass the -follow option to follow files across renames
*
* @default false
*/
follow?: boolean;
/**
* The number of commits to return
*
Expand Down Expand Up @@ -128,6 +134,7 @@ const defaultOptions = {
fields: defaultFields,
nameStatus: true,
includeMergeCommitFiles: false,
follow: false,
findCopiesHarder: false,
all: false,
};
Expand Down Expand Up @@ -258,6 +265,10 @@ function createCommandArguments<
command.push("-m");
}

if (options.follow) {
command.push("--follow");
}

command.push(`-n ${options.number}`);

command = addOptionalArguments(command, options);
Expand Down
17 changes: 17 additions & 0 deletions test/gitlog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 9a5273e

Please sign in to comment.