diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bda809..cc18ae9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,22 @@ All notable changes to the "dwm-git-simpleuse" extension will be documented in this file. -Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. - ## [Unreleased] +- Task API +- no git warnings as errors + +## [0.1.0] - 2024-04-10 + +- choose commmit message +- commit message auto increment +- command to initialize existing repository +- activation event set to "onStartupFinished" + +## [0.0.2] - 2024-02-02 + +- renamed command to something else than "helloworld" => ("full push") + +## [0.0.1] - 2024-02-01 + - Initial release \ No newline at end of file diff --git a/extension.js b/extension.js index 308ca3b..084a2ee 100644 --- a/extension.js +++ b/extension.js @@ -12,7 +12,7 @@ const chp = require("child_process"); 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 - console.log("yo!"); + let lastGitCommitMsg = ""; try { process.chdir(vscode.workspace.workspaceFolders[0].uri.fsPath); @@ -35,10 +35,23 @@ function activate(context) { // 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.helloWorld", - function () { + "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 'test77' && git pull && git push", + `git add . && git commit -am '${gitCommitMsg}' && git pull && git push`, { cwd: vscode.workspace.workspaceFolders[0].uri.fsPath }, (err, stdout, stderr) => { if (err) { @@ -85,7 +98,49 @@ function activate(context) { ); */ } ); + 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; + } + + 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); } @@ -96,3 +151,10 @@ module.exports = { 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})`; + }); +}; diff --git a/package.json b/package.json index 18d4256..4abcf17 100644 --- a/package.json +++ b/package.json @@ -4,27 +4,33 @@ "icon": "img/icon.png", "description": "", "publisher": "nyncral", - "version": "0.0.1", + "version": "0.1.0", "engines": { "vscode": "^1.85.0" }, "categories": [ "Other" ], - "activationEvents": [], + "activationEvents": [ + "onStartupFinished" + ], "main": "./extension.js", "contributes": { "commands": [ { - "command": "dwm-git-simpleuse.helloWorld", - "title": "HelloWorld23" + "command": "dwm-git-simpleuse.fullPush", + "title": "full push" + }, + { + "command": "dwm-git-simpleuse.initRepo", + "title": "initialize existing repository" } ], "keybindings": [ { - "command": "dwm-git-simpleuse.helloWorld", - "key": "ctrl+alt+r", - "mac": "cmd+alt+r" + "command": "dwm-git-simpleuse.fullPush", + "key": "ctrl+alt+s", + "mac": "ctrl+alt+s" } ] }, @@ -43,6 +49,7 @@ "typescript": "^5.3.3" }, "dependencies": { - "child_process": "^1.0.2" + "child_process": "^1.0.2", + "git": "^2.0.0" } }