Skip to content

Commit f64718c

Browse files
committed
Only keep preparation commit if --allow-noop was passed
1 parent dd26938 commit f64718c

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/bin/rustc_josh_sync.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ enum Command {
4242
#[clap(long)]
4343
upstream_commit: Option<String>,
4444

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

@@ -110,7 +112,7 @@ fn main() -> anyhow::Result<()> {
110112
let ctx = load_context(&config_path, &rust_version_path)?;
111113
let josh = get_josh_proxy(verbose)?;
112114
let sync = GitSync::new(ctx.clone(), josh, verbose);
113-
match sync.rustc_pull(upstream_repo, upstream_commit) {
115+
match sync.rustc_pull(upstream_repo, upstream_commit, allow_noop) {
114116
Ok(result) => {
115117
if !maybe_create_gh_pr(
116118
&ctx.config.full_repo_name(),

src/sync.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl GitSync {
4545
&self,
4646
upstream_repo: String,
4747
upstream_commit: Option<String>,
48+
allow_noop: bool,
4849
) -> Result<PullResult, RustcPullError> {
4950
// The upstream commit that we want to pull
5051
let upstream_sha = if let Some(sha) = upstream_commit {
@@ -142,8 +143,13 @@ This updates the rust-version file to {upstream_sha}."#,
142143
)
143144
.context("cannot create preparation commit")?;
144145

145-
// Make sure that we reset the above commit if something fails
146-
let mut git_reset = GitResetOnDrop::new(orig_head, self.verbose);
146+
// Make sure that we reset either to the default HEAD, or the preparation commit, if
147+
// something bad happens
148+
let mut git_reset = if allow_noop {
149+
GitResetOnDrop::new(get_current_head_sha(self.verbose)?, self.verbose)
150+
} else {
151+
GitResetOnDrop::new(orig_head, self.verbose)
152+
};
147153

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

216222
// This is the easy case, no merge was performed, so we bail
217223
if current_sha == sha_pre_merge {
218-
eprintln!(
219-
"No merge was performed, no changes to pull were found. Rolling back the preparation commit."
220-
);
224+
eprintln!("No merge was performed, no changes to pull were found. Rolling back.");
221225
return Err(RustcPullError::NothingToPull);
222226
}
223227

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

0 commit comments

Comments
 (0)