fix(ssh_command): run original command in correct cwd
+ 10
- 4
packages/gitfoss-ssh-command/src/ssh-command.cr
@@ -97,8 +97,8 @@ def run_cmd_capture(cmd : Array(String), cwd = nil)
   { code: code, out: out, err: err }
 end
 
-def exec_replace(cmd : Array(String))
-  Process.exec(cmd[0], cmd[1..-1])
+def exec_replace(cmd : Array(String), cwd : String)
+  Process.exec(cmd[0], cmd[1..-1], chdir: cwd)
 end
 
 # Extract repo path (org/repo.git) from SSH_ORIGINAL_COMMAND argument

...
@@ -168,6 +168,8 @@ end
 AUTH_URL = "https://gitfoss.dev/_ssh/auth"
 TRIGGER_BASE = "https://gitfoss.dev"  # base host for pipeline triggers
 
+write_to_file("", true)
+
 # ---------- Step 1: gather inputs ----------
 
 user = ARGV[0]

...
@@ -184,7 +186,7 @@ if SSH_ORIGINAL_COMMAND.chomp == ""
   die_with_message "Script has not been invoked by ssh. Missing environment variable SSH_ORIGINAL_COMMAND.", 2
 end
 
-write_to_file("new client: #{user} -> #{key_blob} (#{fingerprint || "none"})\n", true)
+write_to_file("new client: #{user} -> #{key_blob} (#{fingerprint || "none"})\n")
 write_to_file("command: #{SSH_ORIGINAL_COMMAND}\n")
 
 org_repo = extract_org_repo(SSH_ORIGINAL_COMMAND)

...
@@ -231,6 +233,10 @@ rescue ex : Exception
   die_with_message("Key validation: error: #{ex.message}")
 end
 
+if repoDir.chomp == ""
+  die_with_message("Could not determine repo_dir from response.")
+end
+
 write_to_file("repo_dir: #{repoDir}\n")
 
 # ---------- Step 3: dispatch by SSH_ORIGINAL_COMMAND ----------

...
@@ -246,7 +252,7 @@ write_to_file("mode: #{mode.to_s}\n")
 
 # For upload (fetch/pull), just exec the original command (auth already done).
 if mode == :upload
-  exec_replace(["/bin/sh", "-c", SSH_ORIGINAL_COMMAND])
+  exec_replace(["/bin/sh", "-c", SSH_ORIGINAL_COMMAND.split(" ")[0]], repoDir)
 end
 
 # ---------- From here: mode == :receive (push) ----------