6 Commits

Author SHA1 Message Date
461bd634a6 bump version 2021-12-06 22:12:13 +03:00
533fe677de Update readme 2021-12-06 22:05:17 +03:00
4788b5403b rename user=>name 2021-12-06 21:52:48 +03:00
eee833f62e fix indent 2021-12-06 21:40:31 +03:00
f305cdd7c3 Change the repository creation method 2021-12-06 21:39:41 +03:00
f38ef7dee3 fix typo 2021-12-06 16:27:31 +03:00
4 changed files with 67 additions and 42 deletions

View File

@@ -1,5 +1,13 @@
# Change Log
All notable changes to this project will be documented in this file.
## [0.0.1]
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.0.2] - 2021-12-06
### Added
- README 😂
### Changed
- Rename `user` => `name` in settings options
## [0.0.1] - 2021-12-06
- Initial release

View File

@@ -1 +1,9 @@
# gitcheck
# Git User Check
Sometimes, after cloning a repository from a corporate server and having already sent several commits there, you notice that you forgot to change the user settings in git.
This extension is written to avoid this.
## Configuration
* `gitcheck.domain` The domain (or just a substring) for which the check will be performed (you can see in the output of the command `git remote -v`)&
* `gitcheck.name` This value will be checked against the value of the git parameter `user.name`.
* `gitcheck.email` This value will be checked against the value of the git parameter `user.email`.

View File

@@ -2,7 +2,7 @@
"name": "gitcheck",
"displayName": "Git User Check",
"description": "Checking the user's compliance with the repository",
"version": "0.0.1",
"version": "0.0.2",
"preview": true,
"engines": {
"vscode": "^1.62.0"
@@ -33,15 +33,15 @@
"properties": {
"gitcheck.domain": {
"type": "string",
"description": "remote domain for check"
"description": "Remote domain for check"
},
"gitcheck.user": {
"gitcheck.name": {
"type":"string",
"description": "Username for gitcheck domain"
"description": "user.name for gitcheck domain"
},
"gitcheck.email": {
"type":"string",
"description": "Email for gitcheck domain"
"description": "user.email for gitcheck domain"
}
}
}

View File

@@ -1,24 +1,33 @@
import * as vscode from 'vscode';
import { GitExtension } from './git';
export function activate() {
export async function activate() {
var conf = vscode.workspace.getConfiguration("gitcheck");
const domain = conf.get<string>("domain");
const user = conf.get<string>("user");
const name = conf.get<string>("name");
const email = conf.get<string>("email");
if (!(domain && user && email)) {
if (!vscode.workspace.workspaceFolders) {
return;
}
if (!(domain && name && email)) {
console.log("Missing config params");
return;
}
const git = vscode.extensions.getExtension<GitExtension>('vscode.git')!.exports.getAPI(1)!;
const repository = git.repositories[0];
const repository = await git.openRepository(vscode.workspace.workspaceFolders[0].uri);
if (!repository) {
return;
}
repository.state.remotes.forEach(async remote => {
const pushUrl = remote.pushUrl;
if (pushUrl && pushUrl.includes(domain)) {
var gitConfig = await repository.getConfigs();
var gitUser:string = "";
var gitName:string = "";
var gitEmail:string = "";
gitConfig = gitConfig.filter( elem => {
return elem.key === "user.name" || elem.key === "user.email";
@@ -30,7 +39,7 @@ export function activate() {
gitConfig.forEach(c => {
switch (c.key) {
case "user.name":
gitUser = c.value;
gitName = c.value;
break;
case "user.email":
@@ -41,7 +50,7 @@ export function activate() {
console.log(c.key);
}
});
if (gitUser !== user || gitEmail !== email) {
if (gitName !== name || gitEmail !== email) {
vscode.window.showErrorMessage("Wrong user creds in git");
}
}