MCPcopy Create free account
hub / github.com/HairlessVillager/minecommit / git_commit_with_parent

Function git_commit_with_parent

minecommit/src/odb/git.rs:318–362  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

316
317 #[test]
318 fn git_commit_with_parent() {
319 let repo = init_bare_repo();
320 let mut odb = LocalGitOdb::from_commit(repo.path().to_path_buf(), String::new()).unwrap();
321
322 odb.put("a.txt", &b"v1".to_vec()).unwrap();
323 let first = odb.commit(&[] as &[&str], "first", None, None).unwrap();
324
325 // Second commit only puts b.txt — a.txt is NOT inherited
326 let mut odb = LocalGitOdb::from_commit(repo.path().to_path_buf(), first.clone()).unwrap();
327 odb.put("b.txt", &b"v2".to_vec()).unwrap();
328 let second = odb.commit(&[&first], "second", None, None).unwrap();
329
330 // second commit's tree contains only b.txt
331 let files: Vec<String> = String::from_utf8(
332 Command::new("git")
333 .args([
334 "--git-dir",
335 repo.path().to_str().expect("repo path is not valid utf-8"),
336 ])
337 .args(["ls-tree", "--name-only", &second])
338 .output()
339 .expect("failed to run git ls-tree")
340 .stdout,
341 )
342 .expect("git ls-tree output is not valid utf-8")
343 .lines()
344 .map(|s| s.to_string())
345 .collect();
346 assert_eq!(files, vec!["b.txt"]);
347
348 // parent linkage is recorded
349 let parent = String::from_utf8(
350 Command::new("git")
351 .args([
352 "--git-dir",
353 repo.path().to_str().expect("repo path is not valid utf-8"),
354 ])
355 .args(["rev-parse", &format!("{second}^1")])
356 .output()
357 .expect("failed to run git rev-parse")
358 .stdout,
359 )
360 .expect("git rev-parse output is not valid utf-8");
361 assert_eq!(parent.trim(), first);
362 }
363}

Callers

nothing calls this directly

Calls 3

init_bare_repoFunction · 0.70
putMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected