0.1.1
This commit is contained in:
parent
b4a04ae19d
commit
ed6154a974
4 changed files with 158 additions and 159 deletions
|
|
@ -6,6 +6,12 @@ All notable changes to the "dwm-git-simpleuse" extension will be documented in t
|
|||
|
||||
- Task API
|
||||
- no git warnings as errors
|
||||
- progress bar for git commands
|
||||
|
||||
## [0.1.1] - 2024-07-11
|
||||
|
||||
- fixed "initialize existing repository" command
|
||||
- renamed commands with "gitDWM : " prefix
|
||||
|
||||
## [0.1.0] - 2024-04-10
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
This extention is in beta, some errors may occur,
|
||||
errors given through vscode notifications can be ignored for most of them,
|
||||
it needs and will improve over time.
|
||||
it needs to and will improve over time.
|
||||
|
|
|
|||
200
extension.js
200
extension.js
|
|
@ -10,67 +10,65 @@ const chp = require("child_process");
|
|||
* @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
|
||||
let lastGitCommitMsg = "";
|
||||
// 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
|
||||
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 (stderr) {
|
||||
vscode.window.showErrorMessage("GITPULL : " + stderr);
|
||||
return;
|
||||
}
|
||||
vscode.window.showInformationMessage("GITPULL : " + stdout);
|
||||
});
|
||||
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 (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
|
||||
let disposable = vscode.commands.registerCommand(
|
||||
"dwm-git-simpleuse.fullPush",
|
||||
async function () {
|
||||
const gitCommitMsg = await vscode.window.showInputBox({
|
||||
placeHolder: "commit message",
|
||||
prompt: "choose your commit message",
|
||||
value: lastGitCommitMsg.incrementSuffixe(),
|
||||
});
|
||||
if (gitCommitMsg === undefined) return;
|
||||
gitCommitMsg.trim();
|
||||
if (!gitCommitMsg.length) {
|
||||
vscode.window.showErrorMessage("commit message needed");
|
||||
return;
|
||||
}
|
||||
lastGitCommitMsg = gitCommitMsg;
|
||||
// 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
|
||||
let disposable = vscode.commands.registerCommand("dwm-git-simpleuse.fullPush", async function () {
|
||||
const gitCommitMsg = await vscode.window.showInputBox({
|
||||
placeHolder: "commit message",
|
||||
prompt: "choose your commit message",
|
||||
value: lastGitCommitMsg.incrementSuffixe(),
|
||||
});
|
||||
if (gitCommitMsg === undefined) return;
|
||||
gitCommitMsg.trim();
|
||||
if (!gitCommitMsg.length) {
|
||||
vscode.window.showErrorMessage("commit message needed");
|
||||
return;
|
||||
}
|
||||
lastGitCommitMsg = gitCommitMsg;
|
||||
|
||||
chp.exec(
|
||||
`git add . && git commit -am '${gitCommitMsg}' && git pull && git push`,
|
||||
{ cwd: vscode.workspace.workspaceFolders[0].uri.fsPath },
|
||||
(err, stdout, stderr) => {
|
||||
if (err) {
|
||||
vscode.window.showErrorMessage(err.message);
|
||||
return;
|
||||
}
|
||||
if (stderr) {
|
||||
vscode.window.showErrorMessage(stderr);
|
||||
return;
|
||||
}
|
||||
vscode.window.showInformationMessage(stdout);
|
||||
}
|
||||
);
|
||||
/* try {
|
||||
chp.exec(
|
||||
`git add . && git commit -am '${gitCommitMsg}' && git pull && git push`,
|
||||
{ cwd: vscode.workspace.workspaceFolders[0].uri.fsPath },
|
||||
(err, stdout, stderr) => {
|
||||
if (err) {
|
||||
vscode.window.showErrorMessage(err.message);
|
||||
return;
|
||||
}
|
||||
if (stderr) {
|
||||
vscode.window.showErrorMessage(stderr);
|
||||
return;
|
||||
}
|
||||
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) => {
|
||||
/* chp.execFile("git", ["add", "*"], (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
vscode.window.showErrorMessage("GITADD : " + err.message);
|
||||
return;
|
||||
|
|
@ -96,65 +94,61 @@ function activate(context) {
|
|||
vscode.window.showInformationMessage("GITCOM : " + stdout);
|
||||
}
|
||||
); */
|
||||
}
|
||||
);
|
||||
context.subscriptions.push(disposable);
|
||||
});
|
||||
context.subscriptions.push(disposable);
|
||||
|
||||
disposable = vscode.commands.registerCommand(
|
||||
"dwm-git-simpleuse.initRepo",
|
||||
async function () {
|
||||
const gitLink = await vscode.window.showInputBox({
|
||||
placeHolder: "git repo link",
|
||||
prompt: "Initialize a git repository",
|
||||
value: await vscode.env.clipboard.readText(),
|
||||
});
|
||||
if (gitLink === undefined) return;
|
||||
gitLink.trim();
|
||||
if (!gitLink.match(/^https?:\/\/\S+\.git$/).length) {
|
||||
vscode.window.showErrorMessage("Link needed");
|
||||
return;
|
||||
}
|
||||
disposable = vscode.commands.registerCommand("dwm-git-simpleuse.initRepo", async function () {
|
||||
const gitLink = await vscode.window.showInputBox({
|
||||
placeHolder: "git repo link",
|
||||
prompt: "Initialize a git repository",
|
||||
value: await vscode.env.clipboard.readText(),
|
||||
});
|
||||
if (gitLink === undefined) return;
|
||||
gitLink.trim();
|
||||
if (!gitLink.match(/^https?:\/\/\S+\.git$/).length) {
|
||||
vscode.window.showErrorMessage("Link needed");
|
||||
return;
|
||||
}
|
||||
|
||||
let gitBranch = await vscode.window.showInputBox({
|
||||
placeHolder: "git branch",
|
||||
prompt: "choose wich branch to use (defaults to 'main')",
|
||||
value: "main",
|
||||
});
|
||||
if (gitBranch === undefined) return;
|
||||
gitBranch.trim();
|
||||
if (!gitBranch.length) gitBranch = "main";
|
||||
let gitBranch = await vscode.window.showInputBox({
|
||||
placeHolder: "git branch",
|
||||
prompt: "choose wich branch to use (defaults to 'main')",
|
||||
value: "main",
|
||||
});
|
||||
if (gitBranch === undefined) return;
|
||||
gitBranch.trim();
|
||||
if (!gitBranch.length) gitBranch = "main";
|
||||
|
||||
chp.exec(
|
||||
`git init && git remote add origin ${gitLink} && git fetch && git reset origin/${gitBranch} && git branch --set-upstream-to=origin/${gitBranch}`,
|
||||
{ cwd: vscode.workspace.workspaceFolders[0].uri.fsPath },
|
||||
(err, stdout, stderr) => {
|
||||
if (err) {
|
||||
vscode.window.showErrorMessage(err.message);
|
||||
return;
|
||||
}
|
||||
if (stderr) {
|
||||
vscode.window.showErrorMessage(stderr);
|
||||
return;
|
||||
}
|
||||
vscode.window.showInformationMessage(stdout);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
context.subscriptions.push(disposable);
|
||||
chp.exec(
|
||||
`git init && git remote add origin ${gitLink} && git fetch && git checkout -t origin/${gitBranch}`,
|
||||
{ cwd: vscode.workspace.workspaceFolders[0].uri.fsPath },
|
||||
(err, stdout, stderr) => {
|
||||
if (err) {
|
||||
vscode.window.showErrorMessage(err.message);
|
||||
return;
|
||||
}
|
||||
if (stderr) {
|
||||
vscode.window.showErrorMessage(stderr);
|
||||
return;
|
||||
}
|
||||
vscode.window.showInformationMessage(stdout);
|
||||
}
|
||||
);
|
||||
});
|
||||
context.subscriptions.push(disposable);
|
||||
}
|
||||
|
||||
// This method is called when your extension is deactivated
|
||||
function deactivate() {}
|
||||
|
||||
module.exports = {
|
||||
activate,
|
||||
deactivate,
|
||||
activate,
|
||||
deactivate,
|
||||
};
|
||||
|
||||
String.prototype.incrementSuffixe = function () {
|
||||
//if there's no (\d+) at the end of the string, add "(1)" at the end if there's a (\d+) at the end of the string, increment it but keep the original string before it
|
||||
return this.replace(/(\d+)?$/, function (match, p1) {
|
||||
return p1 === undefined ? "(1)" : `(${parseInt(p1) + 1})`;
|
||||
});
|
||||
if (this == "") return "";
|
||||
return this.replace(/(\d+)?$/, function (match, p1) {
|
||||
return p1 === undefined ? "(1)" : `(${parseInt(p1) + 1})`;
|
||||
});
|
||||
};
|
||||
|
|
|
|||
105
package.json
105
package.json
|
|
@ -1,55 +1,54 @@
|
|||
{
|
||||
"name": "dwm-git-simpleuse",
|
||||
"displayName": "DWM_git_simpleUse",
|
||||
"icon": "img/icon.png",
|
||||
"description": "",
|
||||
"publisher": "nyncral",
|
||||
"version": "0.1.0",
|
||||
"engines": {
|
||||
"vscode": "^1.85.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onStartupFinished"
|
||||
],
|
||||
"main": "./extension.js",
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "dwm-git-simpleuse.fullPush",
|
||||
"title": "full push"
|
||||
},
|
||||
{
|
||||
"command": "dwm-git-simpleuse.initRepo",
|
||||
"title": "initialize existing repository"
|
||||
}
|
||||
],
|
||||
"keybindings": [
|
||||
{
|
||||
"command": "dwm-git-simpleuse.fullPush",
|
||||
"key": "ctrl+alt+s",
|
||||
"mac": "ctrl+alt+s"
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"pretest": "npm run lint",
|
||||
"test": "vscode-test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^10.0.6",
|
||||
"@types/node": "18.x",
|
||||
"@types/vscode": "^1.85.0",
|
||||
"@vscode/test-cli": "^0.0.4",
|
||||
"@vscode/test-electron": "^2.3.8",
|
||||
"eslint": "^8.56.0",
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"child_process": "^1.0.2",
|
||||
"git": "^2.0.0"
|
||||
}
|
||||
"name": "dwm-git-simpleuse",
|
||||
"displayName": "DWM_git_simpleUse",
|
||||
"icon": "img/icon.png",
|
||||
"description": "",
|
||||
"publisher": "nyncral",
|
||||
"version": "0.1.0",
|
||||
"engines": {
|
||||
"vscode": "^1.85.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onStartupFinished"
|
||||
],
|
||||
"main": "./extension.js",
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "dwm-git-simpleuse.fullPush",
|
||||
"title": "gitDWM : full push"
|
||||
},
|
||||
{
|
||||
"command": "dwm-git-simpleuse.initRepo",
|
||||
"title": "gitDWM : initialize existing repository"
|
||||
}
|
||||
],
|
||||
"keybindings": [
|
||||
{
|
||||
"command": "dwm-git-simpleuse.fullPush",
|
||||
"key": "ctrl+alt+s",
|
||||
"mac": "ctrl+alt+s"
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"pretest": "npm run lint",
|
||||
"test": "vscode-test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^10.0.6",
|
||||
"@types/node": "18.x",
|
||||
"@types/vscode": "^1.85.0",
|
||||
"@vscode/test-cli": "^0.0.4",
|
||||
"@vscode/test-electron": "^2.3.8",
|
||||
"eslint": "^8.56.0",
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"child_process": "^1.0.2"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue