Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -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"
}
5 changes: 3 additions & 2 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

@ecraig12345 ecraig12345 Jul 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be better to combine these in a single parameter, like range?: { fromRef: string; toRef: string }. That way it's clear that both fromRef and toRef are required, and (in some sense) reduces signature bloat.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if you merge/rebase this, the function moved to src/git/gitUtilities.ts.

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];
Expand Down