- check if in git repository before running commands
- can "disable" extention if not in git repository
This commit is contained in:
parent
20f35ab6e5
commit
519dbb96cf
3 changed files with 74 additions and 63 deletions
|
|
@ -1,16 +1,16 @@
|
|||
# Change Log
|
||||
|
||||
All notable changes to the "dwm-git-simpleuse" extension will be documented in this file.
|
||||
|
||||
## [Unreleased] <span style="font-size:0.5em;">_(not in order)_</span>
|
||||
## [Unreleased] <sub><sup><sub>_(not in order)_</sub></sup></sub>
|
||||
|
||||
- Task API
|
||||
- No git msgs as errors
|
||||
- check if in git repository before running commands
|
||||
- Progress bar for git commands
|
||||
- Upload only active file
|
||||
- Make it possible to receive a webhook to send info to user
|
||||
|
||||
- check if in git repository before running commands
|
||||
- can "disable" extention if not in git repository
|
||||
|
||||
## [0.1.3] - 2024-07-18
|
||||
|
||||
- Fixed "commit message auto increment"
|
||||
|
|
|
|||
115
extension.js
115
extension.js
|
|
@ -1,40 +1,57 @@
|
|||
// The module 'vscode' contains the VS Code extensibility API
|
||||
// Import the module and reference it with the alias vscode in your code below
|
||||
const vscode = require("vscode");
|
||||
const util = require("node:util");
|
||||
const chp = require("child_process");
|
||||
|
||||
// This method is called when your extension is activated
|
||||
// Your extension is activated the very first time the command is executed
|
||||
const execP = util.promisify(chp.exec);
|
||||
|
||||
/**
|
||||
* @param {vscode.ExtensionContext} context
|
||||
*/
|
||||
function activate(context) {
|
||||
// Use the console to output diagnostic information (console.log) and errors (console.error)
|
||||
// This line of code will only be executed once when your extension is activated
|
||||
async function activate(context) {
|
||||
let lastGitCommitMsg = "";
|
||||
|
||||
try {
|
||||
process.chdir(vscode.workspace.workspaceFolders[0].uri.fsPath);
|
||||
} catch (err) {
|
||||
vscode.window.showErrorMessage(err);
|
||||
}
|
||||
chp.execFile("git", ["pull"], (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
vscode.window.showErrorMessage("GITPULL : " + err.message);
|
||||
return;
|
||||
if (await vscode.workspace.getConfiguration("dwm-git-simpleuse", 2).get("isEnabled")) {
|
||||
try {
|
||||
process.chdir(vscode.workspace.workspaceFolders[0].uri.fsPath);
|
||||
} catch (err) {
|
||||
vscode.window.showErrorMessage(err);
|
||||
}
|
||||
if (stderr) {
|
||||
vscode.window.showErrorMessage("GITPULL : " + stderr);
|
||||
return;
|
||||
}
|
||||
vscode.window.showInformationMessage("GITPULL : " + stdout);
|
||||
});
|
||||
|
||||
// The command has been defined in the package.json file
|
||||
// Now provide the implementation of the command with registerCommand
|
||||
// The commandId parameter must match the command field in package.json
|
||||
const { stdout } = await execP(`git rev-parse --is-inside-work-tree || echo false`, {
|
||||
cwd: vscode.workspace.workspaceFolders[0].uri.fsPath,
|
||||
});
|
||||
|
||||
if (stdout.trim() !== "true")
|
||||
vscode.window
|
||||
.showErrorMessage("Not a git repository", "Disable extension for current workspace")
|
||||
.then((e) => {
|
||||
if (e == undefined) return;
|
||||
vscode.workspace.getConfiguration("dwm-git-simpleuse", 2).update("isEnabled", false);
|
||||
});
|
||||
else
|
||||
chp.execFile("git", ["pull", "--ff"], (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
vscode.window.showErrorMessage("GITPULL : " + err.message);
|
||||
return;
|
||||
}
|
||||
if (stderr) {
|
||||
vscode.window.showErrorMessage("GITPULL : " + stderr);
|
||||
return;
|
||||
}
|
||||
vscode.window.showInformationMessage("GITPULL : " + stdout);
|
||||
});
|
||||
}
|
||||
|
||||
let disposable = vscode.commands.registerCommand("dwm-git-simpleuse.fullPush", async function () {
|
||||
if (!(await vscode.workspace.getConfiguration("dwm-git-simpleuse", 2).get("isEnabled"))) {
|
||||
vscode.window
|
||||
.showErrorMessage("Extension disabled", "Enable extension for current workspace")
|
||||
.then((e) => {
|
||||
if (e == undefined) return;
|
||||
vscode.workspace.getConfiguration("dwm-git-simpleuse", 2).update("isEnabled", true);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const gitCommitMsg = await vscode.window.showInputBox({
|
||||
placeHolder: "commit message",
|
||||
prompt: "choose your commit message",
|
||||
|
|
@ -49,7 +66,10 @@ function activate(context) {
|
|||
lastGitCommitMsg = gitCommitMsg;
|
||||
|
||||
chp.exec(
|
||||
`git add . && git commit -am "${gitCommitMsg.replace(/"/g, '\\"')}" && git pull --ff && git push`,
|
||||
`git add . && git commit -am "${gitCommitMsg.replace(
|
||||
/"/g,
|
||||
'\\"'
|
||||
)}" && git pull --ff && git push`,
|
||||
{ cwd: vscode.workspace.workspaceFolders[0].uri.fsPath },
|
||||
(err, stdout, stderr) => {
|
||||
if (err) {
|
||||
|
|
@ -63,41 +83,20 @@ function activate(context) {
|
|||
vscode.window.showInformationMessage(stdout);
|
||||
}
|
||||
);
|
||||
/* try {
|
||||
process.chdir(vscode.workspace.workspaceFolders[0].uri.fsPath);
|
||||
} catch (err) {
|
||||
vscode.window.showErrorMessage(err);
|
||||
} */
|
||||
/* chp.execFile("git", ["add", "*"], (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
vscode.window.showErrorMessage("GITADD : " + err.message);
|
||||
return;
|
||||
}
|
||||
if (stderr) {
|
||||
vscode.window.showErrorMessage("GITADD : " + stderr);
|
||||
return;
|
||||
}
|
||||
vscode.window.showInformationMessage("GITADD : " + stdout);
|
||||
});
|
||||
chp.execFile(
|
||||
"git",
|
||||
["commit", "-m test7", "-a"],
|
||||
(err, stdout, stderr) => {
|
||||
if (err) {
|
||||
vscode.window.showErrorMessage("GITCOM : " + err.message);
|
||||
return;
|
||||
}
|
||||
if (stderr) {
|
||||
vscode.window.showErrorMessage("GITCOM : " + stderr);
|
||||
return;
|
||||
}
|
||||
vscode.window.showInformationMessage("GITCOM : " + stdout);
|
||||
}
|
||||
); */
|
||||
});
|
||||
context.subscriptions.push(disposable);
|
||||
|
||||
disposable = vscode.commands.registerCommand("dwm-git-simpleuse.initRepo", async function () {
|
||||
if (!(await vscode.workspace.getConfiguration("dwm-git-simpleuse", 2).get("isEnabled"))) {
|
||||
vscode.window
|
||||
.showErrorMessage("Extension disabled", "Enable extension for current workspace")
|
||||
.then((e) => {
|
||||
if (e == undefined) return;
|
||||
vscode.workspace.getConfiguration("dwm-git-simpleuse", 2).update("isEnabled", true);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const gitLink = await vscode.window.showInputBox({
|
||||
placeHolder: "git repo link",
|
||||
prompt: "Initialize a git repository",
|
||||
|
|
|
|||
14
package.json
14
package.json
|
|
@ -32,7 +32,19 @@
|
|||
"key": "ctrl+alt+s",
|
||||
"mac": "ctrl+alt+s"
|
||||
}
|
||||
]
|
||||
],
|
||||
"configuration": {
|
||||
"type": "object",
|
||||
"title": "DWM Git Simple Use Configuration",
|
||||
"properties": {
|
||||
"dwm-git-simpleuse.isEnabled": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "Enable DWM Git Simple Use extension",
|
||||
"scope": "resource"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
|
|
|
|||
Loading…
Reference in a new issue