Skip to content

Commit

Permalink
feat(hooks): change script prefix to works on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ulthuan committed Sep 22, 2021
1 parent 6638761 commit b076cca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/cli/commands/run_hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ConfigData } from "../../load_config.ts";
import { ArgsForwardingMode, runScript } from "../../run_script.ts";
import { VR_HOOKS } from "../../consts.ts";
import { validateConfigData } from "../../validate_config_data.ts";
import { isScriptObject } from "../../util.ts";
import { isScriptObject, getScriptPrefix } from "../../util.ts";

export class RunHookCommand extends Command {
constructor(private configData: ConfigData | null) {
Expand All @@ -21,10 +21,11 @@ export class RunHookCommand extends Command {
value.gitHook === hook
);
if (script) {
const scriptPrefix = getScriptPrefix();
await runScript({
configData: this.configData!,
script: script[0],
prefix: `GIT_ARGS=("$@");`,
prefix: scriptPrefix,
additionalArgs: args,
argsForwardingMode: ArgsForwardingMode.INDIRECT,
});
Expand Down
10 changes: 10 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ export function makeFileExecutable(filePath: string) {
}
}

export function getScriptPrefix(): string {
let prefix;
if (isWindows) {
prefix = `set GIT_ARGS=("$args");`;
} else {
prefix = `GIT_ARGS=("$@");`;
}
return prefix;
}

export async function spawn(args: string[], cwd?: string): Promise<string> {
const process = Deno.run({
cmd: args,
Expand Down

0 comments on commit b076cca

Please sign in to comment.