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

Function git_stdin_output

atomic-cli/tests/it/git_import_cb9b_test.rs:113–142  ·  view source on GitHub ↗

Run a Git command with stdin and return trimmed stdout (used for plumbing like `commit-tree`, whose stdin carries the commit message).

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

Source from the content-addressed store, hash-verified

111/// Run a Git command with stdin and return trimmed stdout (used for
112/// plumbing like `commit-tree`, whose stdin carries the commit message).
113fn git_stdin_output(root: &Path, args: &[&str], stdin: &[u8]) -> String {
114 let mut child = Command::new("git")
115 .args(args)
116 .current_dir(root)
117 .env("GIT_AUTHOR_NAME", "CB-9B Tests")
118 .env("GIT_AUTHOR_EMAIL", "cb9b@example.com")
119 .env("GIT_COMMITTER_NAME", "CB-9B Tests")
120 .env("GIT_COMMITTER_EMAIL", "cb9b@example.com")
121 .stdin(Stdio::piped())
122 .stdout(Stdio::piped())
123 .stderr(Stdio::piped())
124 .spawn()
125 .expect("run git with stdin");
126 child
127 .stdin
128 .as_mut()
129 .unwrap()
130 .write_all(stdin)
131 .expect("write git stdin");
132 let output = child.wait_with_output().expect("wait for git");
133 assert!(
134 output.status.success(),
135 "git {args:?} failed: {}",
136 String::from_utf8_lossy(&output.stderr)
137 );
138 String::from_utf8(output.stdout)
139 .expect("utf8 git output")
140 .trim()
141 .to_string()
142}
143
144fn atomic_stdin(root: &Path, home: &Path, args: &[&str], stdin: &[u8]) -> Output {
145 let mut child = Command::new(ATOMIC_BIN)

Calls 2

spawnMethod · 0.80
unwrapMethod · 0.45

Tested by

no test coverage detected