MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / git_stdin

Function git_stdin

atomic-cli/tests/it/graph_only_export_cb9b_test.rs:75–100  ·  view source on GitHub ↗

Run a Git command with stdin bytes and return trimmed stdout (for plumbing like `hash-object --stdin`).

(root: &Path, args: &[&str], stdin: &[u8])

Source from the content-addressed store, hash-verified

73/// Run a Git command with stdin bytes and return trimmed stdout (for
74/// plumbing like `hash-object --stdin`).
75fn git_stdin(root: &Path, args: &[&str], stdin: &[u8]) -> String {
76 use std::io::Write as _;
77 use std::process::Stdio;
78 let mut child = Command::new("git")
79 .args(args)
80 .current_dir(root)
81 .env("GIT_CONFIG_NOSYSTEM", "1")
82 .stdin(Stdio::piped())
83 .stdout(Stdio::piped())
84 .stderr(Stdio::piped())
85 .spawn()
86 .expect("run git with stdin");
87 child
88 .stdin
89 .as_mut()
90 .unwrap()
91 .write_all(stdin)
92 .expect("write git stdin");
93 let out = child.wait_with_output().expect("wait for git");
94 assert!(
95 out.status.success(),
96 "git {args:?} failed: {}",
97 String::from_utf8_lossy(&out.stderr)
98 );
99 String::from_utf8_lossy(&out.stdout).trim().to_string()
100}
101
102fn open_repo(root: &Path) -> atomic_repository::Repository {
103 atomic_repository::Repository::open(root).unwrap()

Calls 2

spawnMethod · 0.80
unwrapMethod · 0.45

Tested by

no test coverage detected