|
1 |
| -use std::io::Write; |
2 |
| - |
3 | 1 | #[derive(Clone, Debug)]
|
4 | 2 | pub struct Hooks {
|
5 | 3 | root: std::path::PathBuf,
|
@@ -75,13 +73,45 @@ impl Hooks {
|
75 | 73 | }
|
76 | 74 | let mut process = cmd.spawn()?;
|
77 | 75 | if let Some(stdin) = stdin {
|
| 76 | + use std::io::Write; |
| 77 | + |
78 | 78 | process.stdin.as_mut().unwrap().write_all(stdin)?;
|
79 | 79 | }
|
80 | 80 | let exit = process.wait()?;
|
81 | 81 |
|
82 | 82 | const SIGNAL_EXIT_CODE: i32 = 1;
|
83 | 83 | Ok(exit.code().unwrap_or(SIGNAL_EXIT_CODE))
|
84 | 84 | }
|
| 85 | + |
| 86 | + /// Run `post-rewrite` hook as if called by `git rebase` |
| 87 | + /// |
| 88 | + /// The hook should be run after any automatic note copying (see "notes.rewrite.<command>" in |
| 89 | + /// git-config(1)) has happened, and thus has access to these notes. |
| 90 | + /// |
| 91 | + /// **changedd_shas:** |
| 92 | + /// - For the squash and fixup operation, all commits that were squashed are listed as being rewritten to the squashed commit. This means |
| 93 | + /// that there will be several lines sharing the same new-sha1. |
| 94 | + /// - The commits are must be listed in the order that they were processed by rebase. |
| 95 | + /// - `git` doesn't include entries for dropped commits |
| 96 | + pub fn run_post_rewrite_rebase( |
| 97 | + &self, |
| 98 | + repo: &git2::Repository, |
| 99 | + changed_oids: &[(git2::Oid, git2::Oid)], |
| 100 | + ) -> Result<(), std::io::Error> { |
| 101 | + let name = "post-rewrite"; |
| 102 | + let command = "rebase"; |
| 103 | + let args = [command]; |
| 104 | + let mut stdin = String::new(); |
| 105 | + for (old_oid, new_oid) in changed_oids { |
| 106 | + use std::fmt::Write; |
| 107 | + writeln!(stdin, "{} {}", old_oid, new_oid).expect("Always writeable"); |
| 108 | + } |
| 109 | + |
| 110 | + let code = self.run_hook(repo, name, &args, Some(stdin.as_bytes()), &[])?; |
| 111 | + log::trace!("Hook `{}` failed with code {}", name, code); |
| 112 | + |
| 113 | + Ok(()) |
| 114 | + } |
85 | 115 | }
|
86 | 116 |
|
87 | 117 | const PUSH_HOOKS: &[&str] = &[
|
|
0 commit comments