Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakshmikanth2001 committed Jul 16, 2023
1 parent 218287b commit 2ae17bc
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 111 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"ignorePatterns": [
"out",
"dist",
"node_modules/",
"hook_description.ts",
"**/*.d.ts"
]
}
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,12 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
- regex correction for including `.git/hooks` path in windows OS

### [0.0.14] -- 2023-04-02
- regex correction for including `.git/hooks` for all Operating Systems
- regex correction for including `.git/hooks` for all Operating Systems

### [1.0.0] -- 2023-07-16
- Added configuration to give hook path (just to run and toggle the hooks)
- Improved `runHook` performace by caching git results
- Bug fix for conventional hook run
- Added and option for predefinedHooks(all default hooks supplied by git)
- editor/title regex correction
- galleryBanner color change
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@
* View Git Hooks in current workspace
* Activate git hooks in current workspace
* Edit git hook in current workspace
* Configure git hooks path in current workspace (Doesn't set the git config core.hooksPath)

## Run Git Hooks
![](https://githooks.s3.ap-south-1.amazonaws.com/run_hook.png)

## Git Hooks Configuration
In setting configure GitHooks.hooksDirectory to view hooks in your workspace(
please make sure to set `git config core.hooksPath $HOOKS_PATH` to the same path as configured in the extension
)

## Various Shell path suggetions
![](https://githooks.s3.ap-south-1.amazonaws.com/shell-suggetion.png)

Expand All @@ -22,3 +28,13 @@

## Git Hooks Description
![](https://githooks.s3.ap-south-1.amazonaws.com/hook_hints.png)

# Contributors

A big thanks to the people that have contributed to this project 🙏🏽🙏🏽🙏🏽👨🏽‍💻🧑🏽‍💻:

### By Reporting Issues and bugs

Paul-Joseph de Werk ([@DraakUSA](https://github.com/DraakUSA)) — [Bug](https://github.com/Lakshmikanth2001/GitHooks/issues/9)

Ahmad M ([@9AMTech](https://github.com/9AMTech)) — [Bug](https://github.com/Lakshmikanth2001/GitHooks/issues/5)
44 changes: 10 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 30 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "githooks",
"displayName": "GitHooks -- Simple VS-Code UI for git hooks",
"description": "Integrating Git Hooks to vscode UI; Can View, Edit and Run your local Git Hooks",
"version": "0.0.15",
"version": "1.0.0",
"license": "SEE LICENSE IN LICENSE",
"publisher": "lakshmikanthayyadevara",
"main": "./out/extension.js",
Expand All @@ -23,7 +23,8 @@
"email": "[email protected]"
},
"categories": [
"Other"
"Other",
"SCM Providers"
],
"activationEvents": [
"workspaceContains:.git"
Expand All @@ -39,7 +40,7 @@
"Git Hooks"
],
"galleryBanner": {
"color": "#1e415e",
"color": "#0079FF",
"theme": "dark"
},
"contributes": {
Expand Down Expand Up @@ -109,7 +110,7 @@
],
"editor/title": [
{
"when": "resourcePath =~ /hooks/ && resourcePath =~ /git/",
"when": "resourceDirname in GitHooks.hooksDirectoryList",
"command": "git-hooks.runCurrentHook",
"group": "navigation"
}
Expand Down Expand Up @@ -191,6 +192,30 @@
"type": "boolean",
"default": true,
"description": "Display GitHook icon in activity bar"
},
"GitHooks.hooksDirectory": {
"type": "string",
"default": ".git/hooks",
"description": "Directories to search for git hooks (Doesn't set the git config core.hooksPath)"
},
"GitHooks.predefinedHooks": {
"type": "array",
"default": [
"applypatch-msg",
"commit-msg",
"fsmonitor-watchman",
"post-update",
"pre-applypatch",
"pre-commit",
"pre-merge-commit",
"pre-push",
"pre-rebase",
"pre-receive",
"prepare-commit-msg",
"push-to-checkout",
"update"
],
"description": "Predefined hooks to display"
}
}
},
Expand Down Expand Up @@ -228,7 +253,7 @@
"ts-loader": "^9.4.1",
"typescript": "^4.5.4",
"webpack": "^5.75.0",
"webpack-bundle-analyzer": "^4.8.0",
"webpack-bundle-analyzer": "^4.9.0",
"webpack-cli": "^5.0.0"
},
"dependencies": {
Expand Down
58 changes: 54 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as path from 'path';
import * as vscode from 'vscode';
import { regesterHookTreeDataProvider } from './hooks_data';
import { annotateFirstLine, clearLineAnnotation, initialAnnotation } from './text_decorators';
Expand All @@ -10,6 +11,43 @@ function setEditorLaunguage(editor: vscode.TextEditor, language: string) {
vscode.languages.setTextDocumentLanguage(editor.document, language);
}

async function executeShellCommandSync(command: string) {
if (process.platform === 'win32') {
return await shellComand(command, {
shell: 'C:\\Program Files\\Git\\bin\\bash',
});
} else if (process.platform === 'darwin') {
return await shellComand(command, {
shell: '/bin/bash',
});
} else if (process.platform === 'linux') {
return await shellComand(command, {
shell: '/usr/bin/bash',
});
} else {
vscode.window.showErrorMessage('Unknow OS cannot detect bash shell');
}
}

async function getHooksDir(): Promise<string> {
// get all files in current workspace
// get coreHooksPath by executing this command git config --get core.hooksPath

// pipe error to null
let hooksPath = await executeShellCommandSync('git config --get core.hooksPath &2>/dev/null');

if (hooksPath && hooksPath !== '') {
// store this in vscode setContext
return hooksPath;
}

const workspaceFolders = vscode.workspace.workspaceFolders;
const workspaceFolder = workspaceFolders?.[0];

hooksPath = path.join(workspaceFolder?.uri.fsPath ?? '', '.git', 'hooks');
return hooksPath;
}

function createCustomCompletionItem(
snippetName: string,
completionKind: vscode.CompletionItemKind,
Expand Down Expand Up @@ -38,7 +76,7 @@ function toggleView() {

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
export async function activate(context: vscode.ExtensionContext) {
// 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 activate
console.log('Congratulations, your extension "git-hooks" is now active!');
Expand Down Expand Up @@ -123,8 +161,7 @@ export function activate(context: vscode.ExtensionContext) {
`shebang`,
);
context.subscriptions.push(launguageSnippetProvider);
}
else{
} else {
console.error(`unable to detect ${launguages[index]} launguage path`);
}
});
Expand All @@ -147,7 +184,7 @@ export function activate(context: vscode.ExtensionContext) {
}
});
vscode.workspace.onDidChangeConfiguration((configChange) => {
// get viewContainerDisplay fro configChange
// get viewContainerDisplay for configChange
if (configChange.affectsConfiguration('GitHooks.viewContainerDisplay')) {
const viewContainerDisplay = vscode.workspace.getConfiguration('GitHooks')?.['viewContainerDisplay'] ?? true;
if (viewContainerDisplay) {
Expand All @@ -157,7 +194,20 @@ export function activate(context: vscode.ExtensionContext) {
}
vscode.commands.executeCommand('setContext', 'GitHooks.viewContainerDisplay', viewContainerDisplay);
}
if (configChange.affectsConfiguration('GitHooks.hooksDirectory')) {
const hooksDir = vscode.workspace.getConfiguration('GitHooks')?.['hooksDirectory'] ?? '';

vscode.commands.executeCommand('setContext', 'GitHooks.hooksDirectory', hooksDir);
vscode.commands.executeCommand('setContext', 'GitHooks.hooksDirectoryList', [hooksDir]);

// update hooks directory
regesterHookTreeDataProvider();
}
});

// get hooks path
const hooksDir = await getHooksDir();
vscode.workspace.getConfiguration('GitHooks')?.update('hooksDirectory', hooksDir, vscode.ConfigurationTarget.Global);
regesterHookTreeDataProvider();

vscode.workspace.onDidOpenTextDocument((e) => {
Expand Down
Loading

0 comments on commit 2ae17bc

Please sign in to comment.