Skip to content

Commit

Permalink
chore: ignore detached HEAD (#950)
Browse files Browse the repository at this point in the history
<!-- For Coveo Employees only. Fill this section.

CDX-1184

-->

## Proposed changes

When doing rebases with rewrite actions, commit-msg is a pain because he
doesn't find HEAD with the current command and crash, breaking the
rebase :finnadie:

To solves this, I swapped the command with a similar one found on the
Internet (SWE101)

It returns `HEAD` when in a detached HEAD
It returns `refs/heads/branch-name` otherwise.
  • Loading branch information
louis-bompart authored Sep 28, 2022
1 parent f4ac6be commit 62d4908
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions hooks/commit-msg.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ const urlBaseRegex = /https:\/\/coveord\.atlassian\.net\/browse/;
const projectAcronym = 'CDX';

let issueNumber;
const branchName = childProcess
.execSync('git symbolic-ref --short HEAD', {encoding: 'utf8'})
let branchName = childProcess
.execSync('git rev-parse --symbolic-full-name HEAD', {encoding: 'utf8'})
.trim();
const issueRegex = new RegExp(projectAcronym + '-[\\d]+', 'i');

if (branchName === 'HEAD') {
process.exit();
} else {
branchName = branchName.split('refs/heads/')[1];
}
const match = branchName.match(issueRegex);
if (match) {
issueNumber = match[0].toUpperCase();
Expand Down

0 comments on commit 62d4908

Please sign in to comment.