Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add follow option #102

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading