deno.land / x / velociraptor@1.5.0 / src / git_hooks.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { blue, existsSync, path } from "../deps.ts";import { isScriptObject, makeFileExecutable, spawn } from "./util.ts";import { version } from "./version.ts";import { VR_HOOKS, VR_MARK } from "./consts.ts";import { ConfigData } from "./load_config.ts";
export const hooks = [ "applypatch-msg", "pre-applypatch", "post-applypatch", "pre-commit", "pre-merge-commit", "prepare-commit-msg", "commit-msg", "post-commit", "pre-rebase", "post-checkout", "post-merge", "pre-push", "post-update", "push-to-checkout", "pre-auto-gc", "post-rewrite", "sendemail-validate",];
function hookScript(hook: string): string { return `#!/bin/sh# ${VR_MARK} ${version}vr run-hook ${hook} "$@"`;}
function areGitHooksInstalled(gitDir: string): boolean { return existsSync(path.join(gitDir, "hooks", ".velociraptor"));}
function installGitHooks(gitDir: string) { const hooksDir = path.join(gitDir, "hooks"); hooks.forEach((hook) => { const hookFile = path.join(hooksDir, hook); if (existsSync(hookFile)) { Deno.renameSync(hookFile, `${hookFile}.bkp`); } Deno.writeTextFileSync(hookFile, hookScript(hook)); makeFileExecutable(hookFile); }); Deno.writeTextFileSync(path.join(hooksDir, ".velociraptor"), ""); console.log(`${blue("Git hooks successfully installed")} `);}
export async function checkGitHooks(configData: ConfigData) { if (Deno.env.get(VR_HOOKS) === "false") return; try { const gitDir = await spawn( ["git", "rev-parse", "--git-common-dir"], configData.cwd, ); const absGitDir = path.join(configData.cwd, gitDir.trim()); if ( !areGitHooksInstalled(absGitDir) && Object.values(configData.config.scripts) .filter(isScriptObject) .some((s: any) => { return "gitHook" in s && hooks.includes(s.gitHook); }) ) { installGitHooks(absGitDir); } } catch (e) { // Not a git repo }}
export function getScriptPrefix(shell: string): string { let prefix; const nameShell = path.basename(shell); switch (nameShell) { case "powershell.exe": prefix = `set GIT_ARGS=("$args");`; break; case "fish": prefix = `set GIT_ARGS $argv;`; break; case "bash": case "zsh": default: prefix = `GIT_ARGS=("$0" "$@");`; break; } return prefix;}
velociraptor

Version Info

Tagged at
2 years ago