Skip to content

Commit ad7c511

Browse files
committed
skip remote access if pre_push not set
1 parent 38f2716 commit ad7c511

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

asyncgit/src/sync/hooks.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ pub fn hooks_pre_push(
150150
scope_time!("hooks_pre_push");
151151

152152
let repo = repo(repo_path)?;
153+
if !git2_hooks::hook_available(
154+
&repo,
155+
None,
156+
git2_hooks::HOOK_PRE_PUSH,
157+
)? {
158+
return Ok(HookResult::Ok);
159+
}
160+
153161
let advertised = advertised_remote_refs(repo_path, remote, url)?;
154162
let updates = match push {
155163
PrePushTarget::Branch { branch, delete } => {

git2-hooks/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ pub const HOOK_PRE_PUSH: &str = "pre-push";
4848

4949
const HOOK_COMMIT_MSG_TEMP_FILE: &str = "COMMIT_EDITMSG";
5050

51+
/// Check if a given hook is present considering config/paths and optional extra paths.
52+
pub fn hook_available(
53+
repo: &Repository,
54+
other_paths: Option<&[&str]>,
55+
hook: &str,
56+
) -> Result<bool> {
57+
let hook = HookPaths::new(repo, other_paths, hook)?;
58+
Ok(hook.found())
59+
}
60+
5161
#[derive(Clone, Debug, PartialEq, Eq)]
5262
pub struct PrePushRef {
5363
pub local_ref: String,

0 commit comments

Comments
 (0)