|
| 1 | +use crate::sync::PUSH_PR_DESCRIPTION; |
1 | 2 | use crate::utils::{FileUpdater, UpdateStatus, Version, parse_cargo_package};
|
2 |
| -use std::fmt::Write; |
| 3 | + |
| 4 | +use std::fmt::{Display, Write}; |
| 5 | + |
| 6 | +use clap::ValueEnum; |
| 7 | +use xshell::{Shell, cmd}; |
3 | 8 |
|
4 | 9 | static CARGO_TOML_FILES: &[&str] = &[
|
5 | 10 | "clippy_config/Cargo.toml",
|
@@ -28,3 +33,47 @@ pub fn bump_version(mut version: Version) {
|
28 | 33 | });
|
29 | 34 | }
|
30 | 35 | }
|
| 36 | + |
| 37 | +#[derive(ValueEnum, Copy, Clone)] |
| 38 | +pub enum Branch { |
| 39 | + Stable, |
| 40 | + Beta, |
| 41 | + Master, |
| 42 | +} |
| 43 | + |
| 44 | +impl Display for Branch { |
| 45 | + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 46 | + match self { |
| 47 | + Branch::Stable => write!(f, "stable"), |
| 48 | + Branch::Beta => write!(f, "beta"), |
| 49 | + Branch::Master => write!(f, "master"), |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +pub fn rustc_clippy_commit(rustc_path: String, branch: Branch) { |
| 55 | + let sh = Shell::new().expect("failed to create shell"); |
| 56 | + sh.change_dir(rustc_path); |
| 57 | + |
| 58 | + let base = branch.to_string(); |
| 59 | + cmd!(sh, "git fetch https://github.com/rust-lang/rust {base}") |
| 60 | + .run() |
| 61 | + .expect("failed to fetch base commit"); |
| 62 | + let last_rustup_commit = cmd!( |
| 63 | + sh, |
| 64 | + "git log -1 --merges --grep=\"{PUSH_PR_DESCRIPTION}\" FETCH_HEAD -- src/tools/clippy" |
| 65 | + ) |
| 66 | + .read() |
| 67 | + .expect("failed to run git log"); |
| 68 | + |
| 69 | + let commit = last_rustup_commit |
| 70 | + .lines() |
| 71 | + .find(|c| c.contains("Sync from Clippy commit:")) |
| 72 | + .expect("no commit found") |
| 73 | + .trim() |
| 74 | + .rsplit_once('@') |
| 75 | + .expect("no commit hash found") |
| 76 | + .1; |
| 77 | + |
| 78 | + println!("{commit}"); |
| 79 | +} |
0 commit comments