assert(state->msg);
if (!state->no_verify)
- ret = run_hooks_l("applypatch-msg", am_path(state, "final-commit"), NULL);
+ ret = run_hooks_l(the_repository, "applypatch-msg",
+ am_path(state, "final-commit"), NULL);
if (!ret) {
FREE_AND_NULL(state->msg);
strvec_push(&opt.args, "rebase");
opt.path_to_stdin = am_path(state, "rewritten");
- return run_hooks_opt("post-rewrite", &opt);
+ return run_hooks_opt(the_repository, "post-rewrite", &opt);
}
/**
const char *reflog_msg, *author, *committer = NULL;
struct strbuf sb = STRBUF_INIT;
- if (!state->no_verify && run_hooks("pre-applypatch"))
+ if (!state->no_verify && run_hooks(the_repository, "pre-applypatch"))
exit(1);
if (write_index_as_tree(&tree, the_repository->index, get_index_file(), 0, NULL))
fclose(fp);
}
- run_hooks("post-applypatch");
+ run_hooks(the_repository, "post-applypatch");
free_commit_list(parents);
strbuf_release(&sb);
for (p = hook_name_list; *p; p++) {
const char *hook = *p;
- if (hook_exists(hook))
+ if (hook_exists(the_repository, hook))
strbuf_addf(hook_info, "%s\n", hook);
}
}
static int post_checkout_hook(struct commit *old_commit, struct commit *new_commit,
int changed)
{
- return run_hooks_l("post-checkout",
+ return run_hooks_l(the_repository, "post-checkout",
oid_to_hex(old_commit ? &old_commit->object.oid : null_oid()),
oid_to_hex(new_commit ? &new_commit->object.oid : null_oid()),
changed ? "1" : "0", NULL);
if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))
die(_("unable to write new index file"));
- err |= run_hooks_l("post-checkout", oid_to_hex(null_oid()),
+ err |= run_hooks_l(the_repository, "post-checkout", oid_to_hex(null_oid()),
oid_to_hex(&oid), "1", NULL);
if (!err && (option_recurse_submodules.nr > 0)) {
else
return 0;
- if (run_hooks("pre-auto-gc"))
+ if (run_hooks(the_repository, "pre-auto-gc"))
return 0;
return 1;
}
hook_name = argv[0];
if (!ignore_missing)
opt.error_if_missing = 1;
- ret = run_hooks_opt(hook_name, &opt);
+ ret = run_hooks_opt(the_repository, hook_name, &opt);
if (ret < 0) /* error() return */
ret = 1;
return ret;
}
/* Run a post-merge hook */
- run_hooks_l("post-merge", squash ? "1" : "0", NULL);
+ run_hooks_l(the_repository, "post-merge", squash ? "1" : "0", NULL);
if (new_head)
apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
/* If a hook exists, give it a chance to interrupt*/
if (!ok_to_skip_pre_rebase &&
- run_hooks_l("pre-rebase", options.upstream_arg,
+ run_hooks_l(the_repository, "pre-rebase", options.upstream_arg,
argc ? argv[0] : NULL, NULL))
die(_("The pre-rebase hook refused to rebase."));
struct child_process proc = CHILD_PROCESS_INIT;
struct async muxer;
int code;
- const char *hook_path = find_hook(hook_name);
+ const char *hook_path = find_hook(the_repository, hook_name);
if (!hook_path)
return 0;
{
struct child_process proc = CHILD_PROCESS_INIT;
int code;
- const char *hook_path = find_hook("update");
+ const char *hook_path = find_hook(the_repository, "update");
if (!hook_path)
return 0;
int hook_use_push_options = 0;
int version = 0;
int code;
- const char *hook_path = find_hook("proc-receive");
+ const char *hook_path = find_hook(the_repository, "proc-receive");
if (!hook_path) {
rp_error("cannot find hook 'proc-receive'");
strvec_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree));
strvec_pushv(&opt.env, env->v);
strvec_push(&opt.args, hash_to_hex(hash));
- if (run_hooks_opt(push_to_checkout_hook, &opt))
+ if (run_hooks_opt(the_repository, push_to_checkout_hook, &opt))
return "push-to-checkout hook declined";
else
return NULL;
struct child_process proc = CHILD_PROCESS_INIT;
const char *hook;
- hook = find_hook("post-update");
+ hook = find_hook(the_repository, "post-update");
if (!hook)
return;
NULL);
opt.dir = path;
- ret = run_hooks_opt("post-checkout", &opt);
+ ret = run_hooks_opt(the_repository, "post-checkout", &opt);
}
strvec_clear(&child_env);
va_end(args);
opt.invoked_hook = invoked_hook;
- return run_hooks_opt(name, &opt);
+ return run_hooks_opt(the_repository, name, &opt);
}
#include "environment.h"
#include "setup.h"
-const char *find_hook(const char *name)
+const char *find_hook(struct repository *r, const char *name)
{
static struct strbuf path = STRBUF_INIT;
int found_hook;
strbuf_reset(&path);
- strbuf_git_path(&path, "hooks/%s", name);
+ strbuf_repo_git_path(&path, r, "hooks/%s", name);
found_hook = access(path.buf, X_OK) >= 0;
#ifdef STRIP_EXTENSION
if (!found_hook) {
return path.buf;
}
-int hook_exists(const char *name)
+int hook_exists(struct repository *r, const char *name)
{
- return !!find_hook(name);
+ return !!find_hook(r, name);
}
static int pick_next_hook(struct child_process *cp,
strvec_clear(&options->args);
}
-int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options)
+int run_hooks_opt(struct repository *r, const char *hook_name,
+ struct run_hooks_opt *options)
{
struct strbuf abs_path = STRBUF_INIT;
struct hook_cb_data cb_data = {
.hook_name = hook_name,
.options = options,
};
- const char *const hook_path = find_hook(hook_name);
+ const char *const hook_path = find_hook(r, hook_name);
int ret = 0;
const struct run_process_parallel_opts opts = {
.tr2_category = "hook",
return ret;
}
-int run_hooks(const char *hook_name)
+int run_hooks(struct repository *r, const char *hook_name)
{
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
- return run_hooks_opt(hook_name, &opt);
+ return run_hooks_opt(r, hook_name, &opt);
}
-int run_hooks_l(const char *hook_name, ...)
+int run_hooks_l(struct repository *r, const char *hook_name, ...)
{
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
va_list ap;
strvec_push(&opt.args, arg);
va_end(ap);
- return run_hooks_opt(hook_name, &opt);
+ return run_hooks_opt(r, hook_name, &opt);
}
#define HOOK_H
#include "strvec.h"
+struct repository;
+
struct run_hooks_opt
{
/* Environment vars to be set for each hook */
* or disabled. Note that this points to static storage that will be
* overwritten by further calls to find_hook and run_hook_*.
*/
-const char *find_hook(const char *name);
+const char *find_hook(struct repository *r, const char *name);
/**
* A boolean version of find_hook()
*/
-int hook_exists(const char *hookname);
+int hook_exists(struct repository *r, const char *hookname);
/**
* Takes a `hook_name`, resolves it to a path with find_hook(), and
* Returns the status code of the run hook, or a negative value on
* error().
*/
-int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options);
+int run_hooks_opt(struct repository *r, const char *hook_name,
+ struct run_hooks_opt *options);
/**
* A wrapper for run_hooks_opt() which provides a dummy "struct
* run_hooks_opt" initialized with "RUN_HOOKS_OPT_INIT".
*/
-int run_hooks(const char *hook_name);
+int run_hooks(struct repository *r, const char *hook_name);
/**
* Like run_hooks(), a wrapper for run_hooks_opt().
* hook. This function behaves like the old run_hook_le() API.
*/
LAST_ARG_MUST_BE_NULL
-int run_hooks_l(const char *hook_name, ...);
+int run_hooks_l(struct repository *r, const char *hook_name, ...);
#endif
else
ret = close_lock_file_gently(lock);
- run_hooks_l("post-index-change",
- istate->updated_workdir ? "1" : "0",
- istate->updated_skipworktree ? "1" : "0", NULL);
+ run_hooks_l(the_repository, "post-index-change",
+ istate->updated_workdir ? "1" : "0",
+ istate->updated_skipworktree ? "1" : "0", NULL);
istate->updated_workdir = 0;
istate->updated_skipworktree = 0;
const char *hook;
int ret = 0, i;
- hook = find_hook("reference-transaction");
+ hook = find_hook(transaction->ref_store->repo, "reference-transaction");
if (!hook)
return ret;
reflog_head);
}
if (!ret && run_hook)
- run_hooks_l("post-checkout",
+ run_hooks_l(the_repository, "post-checkout",
oid_to_hex(head ? head : null_oid()),
oid_to_hex(oid), "1", NULL);
strbuf_release(&msg);
struct child_process proc = CHILD_PROCESS_INIT;
int code;
struct strbuf sb = STRBUF_INIT;
- const char *hook_path = find_hook("post-rewrite");
+ const char *hook_path = find_hook(the_repository, "post-rewrite");
if (!hook_path)
return 0;
}
}
- if (hook_exists("prepare-commit-msg")) {
+ if (hook_exists(r, "prepare-commit-msg")) {
res = run_prepare_commit_msg_hook(r, msg, hook_commit);
if (res)
goto out;
hook_opt.path_to_stdin = rebase_path_rewritten_list();
strvec_push(&hook_opt.args, "rebase");
- run_hooks_opt("post-rewrite", &hook_opt);
+ run_hooks_opt(r, "post-rewrite", &hook_opt);
}
apply_autostash(rebase_path_autostash());
struct ref *r;
struct child_process proc = CHILD_PROCESS_INIT;
struct strbuf buf;
- const char *hook_path = find_hook("pre-push");
+ const char *hook_path = find_hook(the_repository, "pre-push");
if (!hook_path)
return 0;