mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-01-14 08:08:05 -05:00
Compare commits
1 Commits
master
...
revert-70-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78456c4431 |
@@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"trailingComma": "none",
|
"trailingComma": "none",
|
||||||
"singleQuote": true,
|
"singleQuote": true
|
||||||
"semi": true
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import { execa } from 'execa';
|
import { execa } from 'execa';
|
||||||
import fs from 'fs';
|
|
||||||
import os from 'os';
|
|
||||||
import {
|
import {
|
||||||
GenerateCommitMessageErrorEnum,
|
GenerateCommitMessageErrorEnum,
|
||||||
generateCommitMessageWithChatCompletion
|
generateCommitMessageWithChatCompletion
|
||||||
@@ -19,7 +17,7 @@ import {
|
|||||||
isCancel,
|
isCancel,
|
||||||
intro,
|
intro,
|
||||||
multiselect,
|
multiselect,
|
||||||
select,
|
select
|
||||||
} from '@clack/prompts';
|
} from '@clack/prompts';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import { trytm } from '../utils/trytm';
|
import { trytm } from '../utils/trytm';
|
||||||
@@ -62,142 +60,79 @@ ${chalk.grey('——————————————————')}
|
|||||||
${commitMessage}
|
${commitMessage}
|
||||||
${chalk.grey('——————————————————')}`
|
${chalk.grey('——————————————————')}`
|
||||||
);
|
);
|
||||||
|
|
||||||
const promptUserConfirm = async(commitText: string ) => {
|
|
||||||
|
|
||||||
const isCommitConfirmedByUser = await select({
|
const isCommitConfirmedByUser = await confirm({
|
||||||
message: 'Confirm the commit message',
|
message: 'Confirm the commit message?'
|
||||||
options: [
|
});
|
||||||
{value: "yes", label: "Yes"},
|
|
||||||
{value: "no", label: "No"},
|
|
||||||
{value: "edit", label: "Edit"}
|
|
||||||
]
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
if (isCommitConfirmedByUser == "yes" && !isCancel(isCommitConfirmedByUser)) {
|
if (isCommitConfirmedByUser && !isCancel(isCommitConfirmedByUser)) {
|
||||||
const { stdout } = await execa('git', [
|
const { stdout } = await execa('git', [
|
||||||
'commit',
|
'commit',
|
||||||
'-m',
|
'-m',
|
||||||
commitText,
|
commitMessage,
|
||||||
...extraArgs
|
...extraArgs
|
||||||
]);
|
]);
|
||||||
|
|
||||||
outro(`${chalk.green('✔')} successfully committed`);
|
outro(`${chalk.green('✔')} successfully committed`);
|
||||||
|
|
||||||
outro(stdout);
|
outro(stdout);
|
||||||
|
|
||||||
const remotes = await getGitRemotes();
|
const remotes = await getGitRemotes();
|
||||||
|
|
||||||
|
if (!remotes.length) {
|
||||||
|
const { stdout } = await execa('git', ['push']);
|
||||||
|
if (stdout) outro(stdout);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (remotes.length === 1) {
|
||||||
|
const isPushConfirmedByUser = await confirm({
|
||||||
|
message: 'Do you want to run `git push`?'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isPushConfirmedByUser && !isCancel(isPushConfirmedByUser)) {
|
||||||
|
const pushSpinner = spinner();
|
||||||
|
|
||||||
|
pushSpinner.start(`Running \`git push ${remotes[0]}\``);
|
||||||
|
|
||||||
|
const { stdout } = await execa('git', [
|
||||||
|
'push',
|
||||||
|
'--verbose',
|
||||||
|
remotes[0]
|
||||||
|
]);
|
||||||
|
|
||||||
|
pushSpinner.stop(
|
||||||
|
`${chalk.green('✔')} successfully pushed all commits to ${remotes[0]}`
|
||||||
|
);
|
||||||
|
|
||||||
if (!remotes.length) {
|
|
||||||
const { stdout } = await execa('git', ['push']);
|
|
||||||
if (stdout) outro(stdout);
|
if (stdout) outro(stdout);
|
||||||
|
} else {
|
||||||
|
outro('`git push` aborted');
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
const selectedRemote = (await select({
|
||||||
|
message: 'Choose a remote to push to',
|
||||||
|
options: remotes.map((remote) => ({ value: remote, label: remote }))
|
||||||
|
})) as string;
|
||||||
|
|
||||||
if (remotes.length === 1) {
|
if (!isCancel(selectedRemote)) {
|
||||||
const isPushConfirmedByUser = await confirm({
|
const pushSpinner = spinner();
|
||||||
message: 'Do you want to run `git push`?'
|
|
||||||
});
|
|
||||||
|
|
||||||
if (isPushConfirmedByUser && !isCancel(isPushConfirmedByUser)) {
|
pushSpinner.start(`Running \`git push ${selectedRemote}\``);
|
||||||
const pushSpinner = spinner();
|
|
||||||
|
|
||||||
pushSpinner.start(`Running \`git push ${remotes[0]}\``);
|
const { stdout } = await execa('git', ['push', selectedRemote]);
|
||||||
|
|
||||||
const { stdout } = await execa('git', [
|
pushSpinner.stop(
|
||||||
'push',
|
`${chalk.green(
|
||||||
'--verbose',
|
'✔'
|
||||||
remotes[0]
|
)} successfully pushed all commits to ${selectedRemote}`
|
||||||
]);
|
);
|
||||||
|
|
||||||
pushSpinner.stop(
|
if (stdout) outro(stdout);
|
||||||
`${chalk.green('✔')} successfully pushed all commits to ${remotes[0]}`
|
} else outro(`${chalk.gray('✖')} process cancelled`);
|
||||||
);
|
}
|
||||||
|
|
||||||
if (stdout) outro(stdout);
|
|
||||||
} else {
|
|
||||||
const selectedRemote = (await select({
|
|
||||||
message: 'Choose a remote to push to',
|
|
||||||
options: remotes.map((remote) => ({ value: remote, label: remote }))
|
|
||||||
})) as string;
|
|
||||||
|
|
||||||
if (!isCancel(selectedRemote)) {
|
|
||||||
const pushSpinner = spinner();
|
|
||||||
pushSpinner.start(`Running \`git push ${selectedRemote}\``);
|
|
||||||
const { stdout } = await execa('git', ['push', selectedRemote]);
|
|
||||||
pushSpinner.stop(
|
|
||||||
`${chalk.green(
|
|
||||||
'✔'
|
|
||||||
)} successfully pushed all commits to ${selectedRemote}`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (stdout) outro(stdout);
|
|
||||||
} else {
|
|
||||||
outro('`git push` aborted');
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (isCommitConfirmedByUser == "edit" && !isCancel(isCommitConfirmedByUser)) {
|
|
||||||
|
|
||||||
let defaultEditor = process.env.EDITOR || (process.platform === 'win32' ? 'notepad.exe' : 'vi');
|
|
||||||
let defaultOpenCommand
|
|
||||||
let linuxTermFlag = ''
|
|
||||||
|
|
||||||
switch (os.platform()) {
|
|
||||||
case 'darwin':
|
|
||||||
defaultOpenCommand = 'open'
|
|
||||||
break
|
|
||||||
case 'win32':
|
|
||||||
defaultOpenCommand = 'start'
|
|
||||||
break
|
|
||||||
case 'linux':
|
|
||||||
if (
|
|
||||||
defaultEditor == 'vi' ||
|
|
||||||
defaultEditor == 'vim' ||
|
|
||||||
defaultEditor == 'nvim' ||
|
|
||||||
defaultEditor == 'nano' ||
|
|
||||||
defaultEditor == 'micro' ||
|
|
||||||
defaultEditor == 'emacs'
|
|
||||||
) {
|
|
||||||
defaultOpenCommand = 'x-terminal-emulator'
|
|
||||||
linuxTermFlag = '-e'
|
|
||||||
break
|
|
||||||
} else {
|
|
||||||
defaultOpenCommand = 'xdg-open'
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.writeFileSync('tmp_commit.txt', commitText);
|
|
||||||
|
|
||||||
outro('🙏 Please close the file when you are done editing it.')
|
|
||||||
|
|
||||||
const { } = await execa(`${defaultOpenCommand}`, [linuxTermFlag, defaultEditor, 'tmp_commit.txt']);
|
|
||||||
|
|
||||||
process.stdin.resume();
|
|
||||||
|
|
||||||
const updatedCommitMessage = fs.readFileSync('tmp_commit.txt', 'utf-8');
|
|
||||||
const updatedCommitMessageTrimmed = updatedCommitMessage.trim()
|
|
||||||
|
|
||||||
fs.unlinkSync('tmp_commit.txt');
|
|
||||||
|
|
||||||
outro(
|
|
||||||
`Commit message:
|
|
||||||
${chalk.grey('——————————————————')}
|
|
||||||
${updatedCommitMessageTrimmed}
|
|
||||||
${chalk.grey('——————————————————')}`
|
|
||||||
)
|
|
||||||
|
|
||||||
await promptUserConfirm(updatedCommitMessage)
|
|
||||||
|
|
||||||
} else if (isCommitConfirmedByUser == "no" && !isCancel(isCommitConfirmedByUser)) {
|
|
||||||
outro(`👋 exiting`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await promptUserConfirm(commitMessage)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function commit(
|
export async function commit(
|
||||||
|
|||||||
Reference in New Issue
Block a user