aboutsummaryrefslogtreecommitdiff
path: root/src/integration/command.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/integration/command.rs')
-rw-r--r--src/integration/command.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/integration/command.rs b/src/integration/command.rs
index a5d58f0c..144fab4a 100644
--- a/src/integration/command.rs
+++ b/src/integration/command.rs
@@ -1,5 +1,8 @@
use std::path::Path;
+#[cfg(any(windows, test))]
+use base64::Engine;
+
pub(crate) fn shell_single_quote(value: &str) -> String {
format!("'{}'", value.replace('\'', "'\"'\"'"))
}
@@ -30,6 +33,18 @@ pub(crate) fn hook_command(hook_path: &Path, action: Option<&str>) -> String {
}
}
+#[cfg(any(windows, test))]
+pub(crate) fn powershell_encoded_hook_command(hook_path: &Path, action: &str) -> String {
+ let path = hook_path.display().to_string().replace('\'', "''");
+ let script = format!("& '{path}' {action}");
+ let encoded_script = script
+ .encode_utf16()
+ .flat_map(u16::to_le_bytes)
+ .collect::<Vec<_>>();
+ let encoded = base64::engine::general_purpose::STANDARD.encode(encoded_script);
+ format!("powershell -NoProfile -ExecutionPolicy Bypass -EncodedCommand {encoded}")
+}
+
pub(crate) fn legacy_bash_hook_command(hook_path: &Path, action: Option<&str>) -> String {
let mut command = format!(
"bash {}",