Skip to content

Commit

Permalink
feat(hooks): backup user-defined hooks before installing
Browse files Browse the repository at this point in the history
  • Loading branch information
umbopepato committed Mar 18, 2021
1 parent 0b6862d commit 39ab6be
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/git_hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { blue, existsSync, path } from "../deps.ts";
import { isScriptObject, spawn } from "./util.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";
Expand Down Expand Up @@ -39,12 +39,11 @@ function installGitHooks(gitDir: string) {
const hooksDir = path.join(gitDir, "hooks");
hooks.forEach((hook) => {
const hookFile = path.join(hooksDir, hook);
Deno.writeTextFileSync(hookFile, hookScript(hook));
try {
Deno.chmodSync(hookFile, 0o0755);
} catch (e) {
// Windows
if (existsSync(hookFile)) {
Deno.renameSync(hookFile, `${hookFile}.bkp`);
}
Deno.writeTextFileSync(hookFile, hookScript(hook));
makeFileExecutable(hookFile);
});
Deno.writeTextFileSync(path.join(hooksDir, ".velociraptor"), "");
console.log(`
Expand Down

0 comments on commit 39ab6be

Please sign in to comment.