diff --git a/.vscode/settings.json b/.vscode/settings.json index 31701b1..4b9304d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,4 @@ // Place your settings in this file to overwrite default and user settings. { - "typescript.surveys.enabled": false, - "terminal.integrated.cwd": "C:\\Users\\Benjamin\\Desktop\\project\\emojis4git" + "typescript.surveys.enabled": false } diff --git a/src/gitmojiCommit/composeCommit.js b/src/gitmojiCommit/composeCommit.js index 0c28222..9b9a479 100644 --- a/src/gitmojiCommit/composeCommit.js +++ b/src/gitmojiCommit/composeCommit.js @@ -1,13 +1,6 @@ -const { workspace } = require('vscode') -const convertToEmoji = require('./convertToEmoji') +const convertToEmoji = require('./convertToEmoji'); module.exports = (commitType, commitText) => { - const multiline = workspace.getConfiguration().get('gitmoji.multilineCommit') - const emoji = convertToEmoji(commitType) - - if (multiline) { - return `git commit -m $'${emoji} ${commitText}'` - } else { - return `git commit -m "${emoji} ${commitText}"` - } -} + const emoji = convertToEmoji(commitType); + return `${emoji} ${commitText}`; +}; \ No newline at end of file diff --git a/src/gitmojiCommit/doesTerminalExist.js b/src/gitmojiCommit/doesTerminalExist.js deleted file mode 100644 index 239af49..0000000 --- a/src/gitmojiCommit/doesTerminalExist.js +++ /dev/null @@ -1,5 +0,0 @@ -const { window } = require('vscode') - -module.exports = () => { - return window.terminals.length !== 0 -} diff --git a/src/gitmojiCommit/index.js b/src/gitmojiCommit/index.js index 9929821..86701b5 100644 --- a/src/gitmojiCommit/index.js +++ b/src/gitmojiCommit/index.js @@ -1,11 +1,11 @@ const { commands, window } = require('vscode') const getCommitType = require('./getCommitType') const composeCommit = require('./composeCommit') -const sendMessageToTerminal = require('./sendMessageToTerminal') +const sendMessageToSourceControl = require("./sendMessageToSourceControl"); // register this function as gitmojiCommit module.exports = () => - commands.registerCommand('extension.gitmojiCommit', async function() { + commands.registerCommand('extension.gitmojiCommit', async function () { // get the gitmoji commit type const commitType = await getCommitType() // if no type is selected exit and display warning message @@ -25,7 +25,6 @@ module.exports = () => } const commitMessage = composeCommit(commitType, commitText) - - // send the composed message to integrated terminal - sendMessageToTerminal(commitMessage) + // send the composed message to Source Control + sendMessageToSourceControl(commitMessage); }) diff --git a/src/gitmojiCommit/sendMessageToSourceControl.js b/src/gitmojiCommit/sendMessageToSourceControl.js new file mode 100644 index 0000000..6f057cc --- /dev/null +++ b/src/gitmojiCommit/sendMessageToSourceControl.js @@ -0,0 +1,51 @@ +const { workspace, window, extensions } = require('vscode'); + +module.exports = async (commitMessage) => { + // get boolean value of autoCommit setting + const autoCommit = workspace.getConfiguration().get('gitmoji.autoCommit') + + // get built in vscode git extension api + const gitExtension = extensions.getExtension('vscode.git').exports; + const git = gitExtension.getAPI(1); + + // list of workspace repositories + const repos = git.repositories; + // if no repositories show warning message + if (!repos || !repos.length) { + return window.showWarningMessage('You have no active repositories.'); + + // if one repository, just set the commit message + } else if (repos.length === 1) { + if (autoCommit) { + repos[0].commit(commitMessage).catch(e => window.showWarningMessage(e.stdout)); + } else { + setCommit(repos[0], commitMessage) + } + } else { + // gather directory names of all repos + const directories = repos.map((el, i) => { + return el.rootUri.path.split('/').pop() + }); + // allow user to chose directory they want commit to go to + const directory = await window.showQuickPick(directories, { + placeHolder: 'Which repositiory should commit be sent to?', + ignoreFocusOut: true + }); + + if (!directory) { + window.showWarningMessage('Gitmoji Commit: You did not pick a repository.'); + } + // determine index of choice + const index = directories.indexOf(directory); + // Set the Commit Message + if (autoCommit) { + repos[index].commit(commitMessage).catch(e => window.showWarningMessage(e.stdout)); + } else { + setCommit(repos[index], commitMessage); + } + } +}; + +function setCommit(repository, commit) { + repository.inputBox.value = commit; +} \ No newline at end of file diff --git a/src/gitmojiCommit/sendMessageToTerminal.js b/src/gitmojiCommit/sendMessageToTerminal.js deleted file mode 100644 index 534e0c7..0000000 --- a/src/gitmojiCommit/sendMessageToTerminal.js +++ /dev/null @@ -1,70 +0,0 @@ -const { workspace, window, extensions } = require('vscode') -const doesTerminalExist = require('./doesTerminalExist') - -module.exports = async commitMessage => { - // get boolean value of autoCommit setting - // pass as second argument to sendText - const autoCommit = workspace.getConfiguration().get('gitmoji.autoCommit') - - // get boolean value of autoClose setting - const autoClose = workspace.getConfiguration().get('gitmoji.autoClose') - - // if terminal is open assume commit goes to cwd - if (doesTerminalExist()) { - const terminal = window.activeTerminal - terminal.show() - terminal.sendText(commitMessage, autoCommit) - if (autoCommit && autoClose) { - setTimeout(() => terminal.dispose(), 2000) - } - } else { - // no terminals active - // get built in vscode git extension api - const gitExtension = extensions.getExtension('vscode.git').exports - const git = gitExtension.getAPI(1) - - // list of workspace repositories - const repos = git.repositories - // if no repositories show warning message - if (!repos || !repos.length) { - return window.showWarningMessage('You have no active repositories.') - - // if one repository create a new terminal and put commit message there - } else if (repos.length === 1) { - const cwd = repos[0].rootUri.path.slice(1) - // create new terminal - const terminal = window.createTerminal({ cwd }) - terminal.show() - terminal.sendText(commitMessage, autoCommit) - if (autoCommit && autoClose) { - setTimeout(() => terminal.dispose(), 2000) - } - // handle multi repository workspaces - } else { - // gather directory names of all repos - const directories = repos.map((el, i) => { - return el.rootUri.path.split('/').pop() - }) - // allow user to chose directory they want commit to go to - const directory = await window.showQuickPick(directories, { - placeHolder: 'Which repositiory should commit be sent to?', - ignoreFocusOut: true - }) - - if (!directory) { - window.showWarningMessage('Gitmoji Commit: You did not pick a repository.') - } - // determine index of choice - const index = directories.indexOf(directory) - // remove leading / from path - const cwd = repos[index].rootUri.path.slice(1) - // create terminal at cwd - const terminal = window.createTerminal({ cwd }) - terminal.show() - terminal.sendText(commitMessage, autoCommit) - if (autoCommit && autoClose) { - setTimeout(() => terminal.dispose(), 2000) - } - } - } -}