Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ef06c9a

Browse files
committedMay 17, 2025
Implement release subcommand in clippy_dev
This is a QoL improvement for doing releases. The `release bump_version` subcommand increments the version in all relevant `Cargo.toml` files. The `release commit` command will only work with the new Josh syncs. Until then the old way, using `git log` has to be used.
1 parent 1445bd6 commit ef06c9a

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed
 

‎clippy_dev/src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ fn main() {
9696
},
9797
DevCommand::Release(ReleaseCommand { subcommand }) => match subcommand {
9898
ReleaseSubcommand::BumpVersion => release::bump_version(clippy.version),
99+
ReleaseSubcommand::Commit { repo_path, branch } => release::rustc_clippy_commit(repo_path, branch),
99100
},
100101
}
101102
}
@@ -365,4 +366,11 @@ enum ReleaseSubcommand {
365366
#[command(name = "bump_version")]
366367
/// Bump the version in the Cargo.toml files
367368
BumpVersion,
369+
/// Print the Clippy commit in the rustc repo for the specified branch
370+
Commit {
371+
/// The path to a rustc repo to look for the commit
372+
repo_path: String,
373+
/// For which branch to print the commit
374+
branch: release::Branch,
375+
},
368376
}

‎clippy_dev/src/release.rs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
use crate::sync::PUSH_PR_DESCRIPTION;
12
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};
38

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

0 commit comments

Comments
 (0)
Please sign in to comment.