1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! What rho's own `git` commands share: how they run (`process`), how a
//! git nobody watches is kept from prompting (`prompts`), and the reading
//! of a checkout's `.git` files without running git (`pointers`).
use std::{path::Path, process::Stdio, time::Duration};
use rho_protocol::ClientEnvironment;
mod pointers;
mod process;
mod prompts;
pub(crate) use pointers::{git_dir_at, is_missing, open_regular, read_small};
pub(crate) use process::{
did_not_start, git_failure, output_within, NoOutput, Running, UNTRACKED_FILES,
};
pub(crate) use prompts::{forbid_prompts, SshCommand, SSH_COMMAND_CONFIG, SSH_COMMAND_ENV};
/// Inherited variables that would point `git` at another repository than
/// the one a command names, as when rho runs inside a git hook. Commands
/// rho runs on a repository of its choosing remove them.
pub(crate) const LOCATION_ENV: &[&str] = &[
"GIT_DIR",
"GIT_WORK_TREE",
"GIT_INDEX_FILE",
"GIT_OBJECT_DIRECTORY",
"GIT_ALTERNATE_OBJECT_DIRECTORIES",
"GIT_COMMON_DIR",
"GIT_NAMESPACE",
];
/// How long one `git` command that reads local files may take
/// ([`output_within`]), such as a session's checkout
/// (`pull_requests::checkout`), what `rho/fs/files` asks before it streams,
/// or what `rho/git/*` reads of a repository.
//
// `symbolic-ref` and `remote get-url origin` took 3 to 4 ms on 2026-11-23
// in rho's own worktree. `ls-files -z --deleted`, which stats every tracked
// file, took 10 ms there (3,447 files) and 60 to 70 ms in a made-up
// repository of 100,000 files on 2026-12-03, warm. A tripwire for a hung
// filesystem; each caller says what it does past it.
pub(crate) const GIT_DEADLINE: Duration = Duration::from_secs(5);
/// `git`, to run in `dir` as a host call runs it: with only the client's
/// `environment`, so it is the git the user's shell finds, configured as
/// there, less [`LOCATION_ENV`]; never asking for a password, with no
/// input, and killed when dropped, as when the stream it feeds closes.
pub(crate) fn host_command(dir: &Path, environment: &ClientEnvironment) -> tokio::process::Command {
let mut command = tokio::process::Command::new("git");
command.env_clear().envs(environment.iter());
// After `env_clear`, which forgets the removals made before it.
for name in LOCATION_ENV {
command.env_remove(name);
}
command
.env("GIT_TERMINAL_PROMPT", "0")
.current_dir(dir)
.stdin(Stdio::null())
.kill_on_drop(true);
command
}