Skip to content

Commit 1a402ae

Browse files
committed
fix: resolve relative git refs like HEAD
1 parent adaebfd commit 1a402ae

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/service/retrieveCommitMessages.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,33 @@ export async function retrieveCommitMessages(
1414
process.chdir(repoRoot);
1515
const fs = { promises: fsPromises, readFile, stat, readdir };
1616

17-
// Retrieve the commit logs between the specified commits
17+
const resolvedToCommit = await git.resolveRef({ fs, dir: repoRoot, ref: toCommit });
18+
const resolvedFromCommit = await git.resolveRef({ fs, dir: repoRoot, ref: fromCommit });
19+
20+
// Retrieve the commit logs between the specified commits
1821
const commits = await git.log({
1922
fs,
2023
dir: repoRoot,
21-
ref: toCommit,
24+
ref: resolvedToCommit,
2225
});
2326

2427
const commitMessages: string[] = [];
2528
let collectMessages = false;
2629

2730
for (const commit of commits) {
28-
if (commit.oid === toCommit) {
31+
if (commit.oid === resolvedToCommit) {
2932
collectMessages = true;
3033
}
3134

3235
if (collectMessages) {
33-
// If the commit is the `fromCommit`, break the loop before adding it
34-
if (commit.oid === fromCommit) {
36+
if (commit.oid === resolvedFromCommit) {
3537
break;
3638
}
3739
commitMessages.push(commit.commit.message);
3840
}
3941
}
4042

41-
// Read and compile the regex from the specified file
43+
// Read and compile the regex from the specified file
4244
let regex: RegExp;
4345
const regexFilePath = resolve(repoRoot, '.apextestsgitdeltarc');
4446
try {
@@ -50,7 +52,7 @@ export async function retrieveCommitMessages(
5052
);
5153
}
5254

53-
// Filter messages that match the regex
55+
// Filter messages that match the regex
5456
const matchedMessages: string[] = [];
5557
commitMessages.forEach((message) => {
5658
let match;

test/commands/delta/unit.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ describe('return the delta tests between git commits', () => {
1313
const $$ = new TestContext();
1414
let sfCommandStubs: ReturnType<typeof stubSfCommandUx>;
1515
let fromSha: string;
16-
let toSha: string;
1716
let tempDir: string;
1817
const originalDir = process.cwd();
1918

@@ -30,7 +29,7 @@ describe('return the delta tests between git commits', () => {
3029
'force-app/main/default/classes/TestClass3.cls',
3130
'dummy 11'
3231
);
33-
toSha = await createTemporaryCommit(
32+
await createTemporaryCommit(
3433
'chore: adding new tests Apex::TestClass3 TestClass4::Apex',
3534
'packaged/classes/TestClass4.cls',
3635
'dummy 2'
@@ -51,7 +50,7 @@ describe('return the delta tests between git commits', () => {
5150
});
5251

5352
it('scan the temporary commits and return the delta test class string without any warnings.', async () => {
54-
await ApexTestDelta.run(['--from', fromSha, '--to', toSha]);
53+
await ApexTestDelta.run(['--from', fromSha, '--to', 'HEAD']);
5554
const output = sfCommandStubs.log
5655
.getCalls()
5756
.flatMap((c) => c.args)

0 commit comments

Comments
 (0)