Skip to content

Commit

Permalink
fix: use "Decaffeinate" as the author name in all generated commits (#7)
Browse files Browse the repository at this point in the history
This makes the situation more clear for people reading `git blame` later.
  • Loading branch information
alangpierce authored Sep 3, 2016
1 parent ff9388e commit cbb376e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ Here's what `convert` does in more detail:
leaves a TODO comment to fix any remaining style issues.
6. All post-decaffeinate changes are committed as a third commit.

In all generated commits, "Decaffeinate" is used as the author name (but not the
email address). This makes it clear to people using `git blame` that the file
was generated using decaffeinate, and not necessarily authored by the person who
happened to run the decaffeinate script.

If you want to see the full details, the [source code](src/convert.js) should
hopefully be fairly readable.

Expand Down
12 changes: 9 additions & 3 deletions src/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ Re-run with the "check" command for more details.`);
p => `git mv ${p}.coffee ${p}.js`,
{runInSeries: true});

let gitAuthor = await getGitAuthor();
let renameCommitMsg =
`Decaffeinate: Rename ${pluralize(baseFiles.length, 'file')} from .coffee to .js`;
console.log(`Generating the first commit: "${renameCommitMsg}"...`);
await exec(`git commit -m "${renameCommitMsg}"`);
await exec(`git commit -m "${renameCommitMsg}" --author "${gitAuthor}"`);

await runCommand(
'Moving files back...',
Expand All @@ -60,7 +61,7 @@ Re-run with the "check" command for more details.`);
let decaffeinateCommitMsg =
`Decaffeinate: Convert ${pluralize(baseFiles.length, 'file')} to JS`;
console.log(`Generating the second commit: ${decaffeinateCommitMsg}...`);
await exec(`git commit -m "${decaffeinateCommitMsg}"`);
await exec(`git commit -m "${decaffeinateCommitMsg}" --author "${gitAuthor}"`);

await runWithProgressBar(
'Running eslint --fix on all files...', baseFiles, makeEslintFixFn(config));
Expand All @@ -73,7 +74,7 @@ Re-run with the "check" command for more details.`);
let postProcessCommitMsg =
`Decaffeinate: Run post-processing cleanups on ${pluralize(baseFiles.length, 'file')}`;
console.log(`Generating the third commit: ${postProcessCommitMsg}...`);
await exec(`git commit -m "${postProcessCommitMsg}"`);
await exec(`git commit -m "${postProcessCommitMsg}" --author "${gitAuthor}"`);

console.log(`Successfully ran decaffeinate on ${pluralize(baseFiles.length, 'file')}.`);
}
Expand All @@ -87,6 +88,11 @@ function getBaseFiles(coffeeFiles) {
});
}

async function getGitAuthor() {
let userEmail = (await exec('git config user.email'))[0];
return `Decaffeinate <${userEmail}>`;
}

function makeEslintFixFn(config) {
return async function runEslint(path) {
// Ignore the eslint exit code; it gives useful stdout in the same format
Expand Down
15 changes: 9 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function runCli(args) {
return (await exec(`"${originalCwd}/bin/bulk-decaffeinate" \
--decaffeinate-path "${originalCwd}/node_modules/.bin/decaffeinate" \
--eslint-path "${originalCwd}/node_modules/.bin/eslint" \
${args}`)).toString();
${args}`))[0];
}

function assertIncludes(stdout, substr) {
Expand Down Expand Up @@ -109,11 +109,14 @@ describe('convert', () => {
let decaffeinateStdout = await runCli('convert');
assertIncludes(decaffeinateStdout, 'Successfully ran decaffeinate');

let logStdout = (await exec('git log --pretty=%s')).toString();
assertIncludes(logStdout, `\
Decaffeinate: Convert 2 files to JS
Decaffeinate: Rename 2 files from .coffee to .js
Initial commit`);
let logStdout = (await exec('git log --pretty="%an <%ae> %s"'))[0];
assert.equal(logStdout, `\
Decaffeinate <[email protected]> Decaffeinate: Run post-processing cleanups on 2 files
Decaffeinate <[email protected]> Decaffeinate: Convert 2 files to JS
Decaffeinate <[email protected]> Decaffeinate: Rename 2 files from .coffee to .js
Sample User <[email protected]> Initial commit
`
);
});
});

Expand Down

0 comments on commit cbb376e

Please sign in to comment.