Create a commit from all pending blobs, consuming self. `parents` is a list of 0 or more commit-ish strings. The first becomes the `from` parent and the rest are additional `merge` parents. Each is resolved with the `^0` suffix so that refs and tags are dereferenced to their underlying commit objects. Returns the sha1 of the new commit. When `author_name` and `author_email` are both `Some`, th
(
self,
parents: &[impl AsRef<str>],
message: &str,
author_name: Option<&str>,
author_email: Option<&str>,
)
| 55 | /// `GIT_AUTHOR_*` and `GIT_COMMITTER_*` environment variables are set |
| 56 | /// on the `git commit-tree` process. |
| 57 | pub fn commit( |
| 58 | self, |
| 59 | parents: &[impl AsRef<str>], |
| 60 | message: &str, |
| 61 | author_name: Option<&str>, |
| 62 | author_email: Option<&str>, |
| 63 | ) -> Result<String> { |
| 64 | log::info!("Building Git tree objects"); |
| 65 | let tree_sha = build_tree(self.repo.git_dir(), &self.pending, "")?; |
| 66 | |
| 67 | let mut cmd = git_cmd(self.repo.git_dir(), [] as [&str; 0]); |
| 68 | cmd.arg("commit-tree").arg(&tree_sha); |
| 69 | for parent in parents { |
| 70 | cmd.arg("-p").arg(&format!("{}^0", parent.as_ref())); |
| 71 | } |
| 72 | cmd.arg("-m").arg(message); |
| 73 | if let (Some(name), Some(email)) = (author_name, author_email) { |
| 74 | cmd.env("GIT_AUTHOR_NAME", name) |
| 75 | .env("GIT_AUTHOR_EMAIL", email) |
| 76 | .env("GIT_COMMITTER_NAME", name) |
| 77 | .env("GIT_COMMITTER_EMAIL", email); |
| 78 | } |
| 79 | |
| 80 | let commit = exec(cmd, None) |
| 81 | .context("failed to run commit-tree")? |
| 82 | .trim() |
| 83 | .to_string(); |
| 84 | Ok(commit) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | /// Recursively build tree objects for `entries` rooted at `prefix`. |