Skip to content

Commit 861eb48

Browse files
committed
Keep intermediate git state if --allow-noop was passed
1 parent dd26938 commit 861eb48

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
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: 17 additions & 4 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 {
@@ -215,17 +216,29 @@ After you fix the conflicts, `git add` the changes and run `git merge --continue
215216

216217
// This is the easy case, no merge was performed, so we bail
217218
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-
);
219+
if allow_noop {
220+
git_reset.disarm();
221+
eprintln!(
222+
"No merge was performed, no changes to pull were found. Keeping the intermediate state."
223+
);
224+
} else {
225+
eprintln!(
226+
"No merge was performed, no changes to pull were found. Rolling back the preparation commit."
227+
);
228+
}
221229
return Err(RustcPullError::NothingToPull);
222230
}
223231

224232
// But it can be more tricky - we can have only empty merge/rollup merge commits from
225233
// rustc, so a merge was created, but the in-tree diff can still be empty.
226234
// In that case we also bail.
227235
if self.has_empty_diff(&sha_pre_merge) {
228-
eprintln!("Only empty changes were pulled. Rolling back the preparation commit.");
236+
if allow_noop {
237+
git_reset.disarm();
238+
eprintln!("Only empty changes were pulled. Keeping the intermediate state.");
239+
} else {
240+
eprintln!("Only empty changes were pulled. Rolling back the preparation commit.");
241+
}
229242
return Err(RustcPullError::NothingToPull);
230243
}
231244

0 commit comments

Comments
 (0)