diff --git a/change/workspace-tools-2022-05-06-09-14-39-asmundg-limit-rev-list-search.json b/change/workspace-tools-2022-05-06-09-14-39-asmundg-limit-rev-list-search.json new file mode 100644 index 00000000..495f06a7 --- /dev/null +++ b/change/workspace-tools-2022-05-06-09-14-39-asmundg-limit-rev-list-search.json @@ -0,0 +1,8 @@ +{ + "type": "minor", + "comment": "feat: Support limited search for added file", + "packageName": "workspace-tools", + "email": "asgramme@microsoft.com", + "dependentChangeType": "patch", + "date": "2022-05-06T07:14:39.673Z" +} diff --git a/src/git.ts b/src/git.ts index 58758143..962b046d 100644 --- a/src/git.ts +++ b/src/git.ts @@ -264,8 +264,9 @@ export function getCurrentHash(cwd: string) { /** * Get the commit hash in which the file was first added. */ -export function getFileAddedHash(filename: string, cwd: string) { - const results = git(["rev-list", "HEAD", filename], { cwd }); +export function getFileAddedHash(filename: string, cwd: string, fromRef?: string, toRef?: string) { + const ref = fromRef && toRef ? `${fromRef}..${toRef}` : "HEAD"; + const results = git(["rev-list", ref, filename], { cwd }); if (results.success) { return results.stdout.trim().split("\n").slice(-1)[0];