Skip to content

Commit f198c2c

Browse files
committedNov 26, 2016
fix(commit): 🐛fix commit when message contains '`', fix push when remote not exists
handle '`' in commit message, handle empty remote origin, remove used basic promopt, fix a typo in `commands/index`
1 parent 4c0c162 commit f198c2c

File tree

4 files changed

+13
-30
lines changed

4 files changed

+13
-30
lines changed
 

‎commands/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import isAGitRepository from '../lib/isAGitRepository';
77
import * as console from '../lib/console';
88
import acp from '../lib/acp';
9-
import richPromopt from '../lib/richPrompt';
9+
import prompt from '../lib/prompt';
1010

1111
export default async() => {
1212
if (!isAGitRepository()) {
1313
console.error(`not a git repository`);
1414
process.exit(1);
1515
}
16-
const commitMessage = await richPromopt();
16+
const commitMessage = await prompt();
1717
acp(commitMessage);
1818
};

‎lib/acp.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ export default (commitMessage) => {
2323
const commitCommand = `git commit -m "${commitMessage}"`;
2424
console.info(commitCommand);
2525
sh.exec(commitCommand);
26-
const pushCommand = `git push ${getRemote()} ${getBranch()} --tag`;
27-
console.info(pushCommand);
28-
sh.exec(pushCommand);
26+
// do not push when remove not exists
27+
const remote = getRemote();
28+
if (remote) {
29+
const pushCommand = `git push ${remote} ${getBranch()} --tag`;
30+
console.info(pushCommand);
31+
sh.exec(pushCommand);
32+
}
2933
};

‎lib/basicPrompt.js

-24
This file was deleted.

‎lib/richPrompt.js ‎lib/prompt.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ export default async() => {
104104
const body = wrap(answers.body, wrapOptions);
105105
const footer = wrap(answers.footer, wrapOptions);
106106

107-
return head + '\n\n' + body + '\n\n' + footer;
107+
const commitMessage = `${head}\n\n${body}\n\n${footer}`;
108+
109+
// fix: '`' string in commit message causes command spilt
110+
return commitMessage.replace(/`/g, `\\\``);
108111

109112
};

0 commit comments

Comments
 (0)