Skip to content
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
8 changes: 5 additions & 3 deletions src/bin/rustc_josh_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ enum Command {
#[clap(long)]
upstream_commit: Option<String>,

/// By default, the `pull` command will exit with status code 2 if there is nothing to pull.
/// If you instead want to exit successfully in that case, pass this flag.
/// By default, the `pull` command will exit with status code 2 if there is nothing to pull,
/// and reset git to the original state.
/// If you instead want to exit successfully and keep the intermediate changes
/// in that case, pass this flag.
#[clap(long)]
allow_noop: bool,

Expand Down Expand Up @@ -110,7 +112,7 @@ fn main() -> anyhow::Result<()> {
let ctx = load_context(&config_path, &rust_version_path)?;
let josh = get_josh_proxy(verbose)?;
let sync = GitSync::new(ctx.clone(), josh, verbose);
match sync.rustc_pull(upstream_repo, upstream_commit) {
match sync.rustc_pull(upstream_repo, upstream_commit, allow_noop) {
Ok(result) => {
if !maybe_create_gh_pr(
&ctx.config.full_repo_name(),
Expand Down
16 changes: 10 additions & 6 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl GitSync {
&self,
upstream_repo: String,
upstream_commit: Option<String>,
allow_noop: bool,
) -> Result<PullResult, RustcPullError> {
// The upstream commit that we want to pull
let upstream_sha = if let Some(sha) = upstream_commit {
Expand Down Expand Up @@ -142,8 +143,13 @@ This updates the rust-version file to {upstream_sha}."#,
)
.context("cannot create preparation commit")?;

// Make sure that we reset the above commit if something fails
let mut git_reset = GitResetOnDrop::new(orig_head, self.verbose);
// Make sure that we reset either to the default HEAD, or the preparation commit, if
// something bad happens
let mut git_reset = if allow_noop {
GitResetOnDrop::new(get_current_head_sha(self.verbose)?, self.verbose)
} else {
GitResetOnDrop::new(orig_head, self.verbose)
};

// Fetch given rustc commit.
run_command(&["git", "fetch", &josh_url], self.verbose)
Expand Down Expand Up @@ -215,17 +221,15 @@ After you fix the conflicts, `git add` the changes and run `git merge --continue

// This is the easy case, no merge was performed, so we bail
if current_sha == sha_pre_merge {
eprintln!(
"No merge was performed, no changes to pull were found. Rolling back the preparation commit."
);
eprintln!("No merge was performed, no changes to pull were found. Rolling back.");
return Err(RustcPullError::NothingToPull);
}

// But it can be more tricky - we can have only empty merge/rollup merge commits from
// rustc, so a merge was created, but the in-tree diff can still be empty.
// In that case we also bail.
if self.has_empty_diff(&sha_pre_merge) {
eprintln!("Only empty changes were pulled. Rolling back the preparation commit.");
eprintln!("Only empty changes were pulled. Rolling back.");
return Err(RustcPullError::NothingToPull);
}

Expand Down