Skip to content

Improve commit message of pushes #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ clap = { version = "4", features = ["derive"] }
directories = "6"
toml = "0.8"
serde = { version = "1", features = ["derive"] }
urlencoding = "2"
which = "8"

[profile.release]
Expand Down
20 changes: 17 additions & 3 deletions src/bin/rustc_josh_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_josh_sync::SyncContext;
use rustc_josh_sync::config::{JoshConfig, load_config};
use rustc_josh_sync::josh::{JoshProxy, try_install_josh};
use rustc_josh_sync::sync::{GitSync, RustcPullError, UPSTREAM_REPO};
use rustc_josh_sync::utils::prompt;
use rustc_josh_sync::utils::{get_current_head_sha, prompt};
use std::path::{Path, PathBuf};

const DEFAULT_CONFIG_PATH: &str = "josh-sync.toml";
Expand Down Expand Up @@ -109,10 +109,24 @@ fn main() -> anyhow::Result<()> {
.context("cannot perform push")?;

// Open PR with `subtree update` title to silence the `no-merges` triagebot check
let title = format!("{} subtree update", ctx.config.repo);
let head = get_current_head_sha()?;

let merge_msg = format!(
r#"Subtree update of `{repo}` to https://github.com/{full_repo}/commit/{head}.

Created using https://github.com/rust-lang/josh-sync.

r? @ghost"#,
repo = ctx.config.repo,
full_repo = ctx.config.full_repo_name(),
);

println!(
r#"You can create the rustc PR using the following URL:
https://github.com/{UPSTREAM_REPO}/compare/{username}:{branch}?quick_pull=1&title={}+subtree+update&body=r?+@ghost"#,
ctx.config.repo
https://github.com/{UPSTREAM_REPO}/compare/{username}:{branch}?quick_pull=1&title={}&body={}"#,
urlencoding::encode(&title),
urlencoding::encode(&merge_msg)
);
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/sync.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::SyncContext;
use crate::josh::JoshProxy;
use crate::utils::run_command_at;
use crate::utils::{ensure_clean_git_state, prompt};
use crate::utils::{get_current_head_sha, run_command_at};
use crate::utils::{run_command, stream_command};
use anyhow::{Context, Error};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -64,7 +64,7 @@ impl GitSync {
&self.context.config.construct_josh_filter(),
);

let orig_head = run_command(["git", "rev-parse", "HEAD"])?;
let orig_head = get_current_head_sha()?;
println!(
"previous upstream base: {:?}",
self.context.last_upstream_sha
Expand Down Expand Up @@ -137,8 +137,7 @@ This updates the rust-version file to {upstream_sha}."#,
};
let num_roots_before = num_roots()?;

let sha =
run_command(&["git", "rev-parse", "HEAD"]).context("failed to get current commit")?;
let sha = get_current_head_sha()?;

// The filtered SHA of upstream
let incoming_ref = run_command(["git", "rev-parse", "FETCH_HEAD"])?;
Expand Down Expand Up @@ -170,8 +169,7 @@ This merge was created using https://github.com/rust-lang/josh-sync.
])
.context("FAILED to merge new commits, something went wrong")?;

let current_sha =
run_command(&["git", "rev-parse", "HEAD"]).context("FAILED to get current commit")?;
let current_sha = get_current_head_sha()?;
if current_sha == sha {
eprintln!(
"No merge was performed, no changes to pull were found. Rolling back the preparation commit."
Expand Down Expand Up @@ -261,7 +259,7 @@ This merge was created using https://github.com/rust-lang/josh-sync.
&["git", "fetch", &josh_url, &branch],
&std::env::current_dir().unwrap(),
)?;
let head = run_command(&["git", "rev-parse", "HEAD"])?;
let head = get_current_head_sha()?;
let fetch_head = run_command(&["git", "rev-parse", "FETCH_HEAD"])?;
if head != fetch_head {
return Err(anyhow::anyhow!(
Expand Down
5 changes: 5 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::Context;
use std::path::Path;
use std::process::Command;

Expand Down Expand Up @@ -67,6 +68,10 @@ pub fn ensure_clean_git_state() {
assert!(read.is_empty(), "working directory must be clean");
}

pub fn get_current_head_sha() -> anyhow::Result<String> {
run_command(&["git", "rev-parse", "HEAD"]).context("failed to get current commit")
}

/// Ask a prompt to user and return true if they responded with `y`.
/// Returns `default_response` on CI.
pub fn prompt(prompt: &str, default_response: bool) -> bool {
Expand Down