Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
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
7 changes: 7 additions & 0 deletions lib/git-shell-out-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,13 @@ export default class GitShellOutStrategy {
msg = rawMessage;
}

// if commit template is used, strip commented lines from commit
// to be consistent with command line git.
const template = await this.fetchCommitMessageTemplate();
if (template) {
msg = msg.split('\n').filter(line => !line.startsWith('#')).join('\n');
}

// Determine the cleanup mode.
if (verbatim) {
args.push('--cleanup=verbatim');
Expand Down
19 changes: 19 additions & 0 deletions test/git-strategies.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,24 @@ import * as reporterProxy from '../lib/reporter-proxy';
'and things',
].join('\n'));
});
it('strips commented lines if commit template is used', async function() {
const workingDirPath = await cloneRepository('three-files');
const git = createTestStrategy(workingDirPath);
const templateText = '# this line should be stripped';

const commitMsgTemplatePath = path.join(workingDirPath, '.gitmessage');
await fs.writeFile(commitMsgTemplatePath, templateText, {encoding: 'utf8'});

await git.setConfig('commit.template', commitMsgTemplatePath);
await git.setConfig('commit.cleanup', 'default');
const commitMessage = ['this line should not be stripped', '', 'neither should this one', templateText].join('\n');
await git.commit(commitMessage, {allowEmpty: true, verbatim: true});

const lastCommit = await git.getHeadCommit();
assert.strictEqual(lastCommit.messageSubject, 'this line should not be stripped');
// message body should not contain the template text
assert.strictEqual(lastCommit.messageBody, 'neither should this one');
});
});

describe('when amend option is true', function() {
Expand Down Expand Up @@ -1168,6 +1186,7 @@ import * as reporterProxy from '../lib/reporter-proxy';
beforeEach(async function() {
const workingDirPath = await cloneRepository('multiple-commits');
git = createTestStrategy(workingDirPath);
sinon.stub(git, 'fetchCommitMessageTemplate').returns(null);
});

const operations = [
Expand Down