Skip to content

Commit f2a971a

Browse files
committed
fix: Make --submit --apply honour --keep-going.
It only worked with `--sync`. A submit stopped in the first conflicting rebase and left it in the checkout.
1 parent e75bffe commit f2a971a

4 files changed

Lines changed: 104 additions & 38 deletions

File tree

‎Cargo.lock‎

Lines changed: 29 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ git-stackui --tree --all
8989
# Show the submission plan for a branch and exit
9090
git-stackui --submit branch-name
9191

92+
# Submit it and rebase the other branches onto the new master. A branch that
93+
# conflicts is left as it was.
94+
git-stackui --submit branch-name --apply --keep-going
95+
9296
# Show the plan to fix a diverged branch (converge)
9397
git-stackui --converge branch-name
9498

‎src/main.rs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ struct Args {
4545
#[arg(long)]
4646
apply: bool,
4747

48-
/// With --sync --apply: leave a branch that conflicts as it was and go on
49-
/// with the branches that don't sit on it, instead of stopping in the
50-
/// conflict.
48+
/// With --apply: leave a branch that conflicts as it was and go on with the
49+
/// branches that don't sit on it, instead of stopping in the conflict.
5150
#[arg(long, requires = "apply")]
5251
keep_going: bool,
5352
}
@@ -130,10 +129,16 @@ async fn main() -> anyhow::Result<()> {
130129
return Ok(());
131130
}
132131

132+
let on_conflict = if args.keep_going {
133+
git_stackui::OnConflict::Abort
134+
} else {
135+
git_stackui::OnConflict::Stop
136+
};
137+
133138
if let Some(branch_name) = args.submit {
134139
let plan = git_stackui::build_submit_plan(&args.path, &branch_name)?;
135140
if args.apply {
136-
let results = git_stackui::apply_plan(&args.path, &plan)?;
141+
let results = git_stackui::apply_plan_with(&args.path, &plan, on_conflict)?;
137142
let all_ok = results
138143
.iter()
139144
.all(|r| matches!(r, git_stackui::OpResult::Ok { .. }));
@@ -161,11 +166,6 @@ async fn main() -> anyhow::Result<()> {
161166
if args.apply {
162167
let plan = git_stackui::build_cascade_plan(&args.path, &branch_name)?;
163168
warn_skipped(&plan.skipped_branches);
164-
let on_conflict = if args.keep_going {
165-
git_stackui::OnConflict::Abort
166-
} else {
167-
git_stackui::OnConflict::Stop
168-
};
169169
let results = git_stackui::apply_plan_with(&args.path, &plan, on_conflict)?;
170170
let all_ok = results
171171
.iter()

‎test/apply_cli_tests.rs‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,68 @@ fn cli_apply_submit_executes_and_exits_zero() {
441441
);
442442
}
443443

444+
#[test]
445+
fn cli_apply_submit_keep_going_leaves_a_conflicting_branch_alone() {
446+
let fx = setup_with_remotes();
447+
run_git(&fx.path, &["checkout", "-q", &fx.main_branch]);
448+
commit_file(&fx.path, "conflict.txt", "v0\n", "Add conflict.txt v0");
449+
for remote in ["origin", "upstream"] {
450+
run_git(
451+
&fx.path,
452+
&["push", "-q", remote, &format!("HEAD:{}", fx.main_branch)],
453+
);
454+
}
455+
stack_branch(&fx, "feat", &fx.main_branch, "conflict.txt", "v-feat\n");
456+
run_git(&fx.path, &["push", "-q", "origin", "feat"]);
457+
run_git(
458+
&fx.path,
459+
&["branch", "--set-upstream-to=origin/feat", "feat"],
460+
);
461+
stack_branch(&fx, "other", &fx.main_branch, "conflict.txt", "v-other\n");
462+
stack_branch(&fx, "side", &fx.main_branch, "side.txt", "side");
463+
let feat_tip = run_git(&fx.path, &["rev-parse", "feat"]);
464+
let other_tip = run_git(&fx.path, &["rev-parse", "other"]);
465+
466+
let out = run_git_stackui(&[
467+
"--path",
468+
&fx.path,
469+
"--apply",
470+
"--keep-going",
471+
"--submit",
472+
"feat",
473+
]);
474+
475+
assert!(
476+
!out.status.success(),
477+
"expected non-zero exit for the conflict\nstdout: {}\nstderr: {}",
478+
lossy(&out.stdout),
479+
lossy(&out.stderr)
480+
);
481+
let rebase_dir = run_git(&fx.path, &["rev-parse", "--git-path", "rebase-merge"]);
482+
assert!(
483+
!std::path::Path::new(&fx.path).join(&rebase_dir).exists(),
484+
"no rebase may be left in progress\nstdout: {}",
485+
lossy(&out.stdout)
486+
);
487+
assert_eq!(
488+
run_git(&fx.path, &["rev-parse", "--abbrev-ref", "HEAD"]),
489+
"side"
490+
);
491+
assert_eq!(run_git(&fx.path, &["rev-parse", "other"]), other_tip);
492+
assert_eq!(
493+
run_git(
494+
&fx.path,
495+
&["rev-parse", &format!("upstream/{}", fx.main_branch)]
496+
),
497+
feat_tip
498+
);
499+
assert_eq!(
500+
run_git(&fx.path, &["merge-base", "side", &fx.main_branch]),
501+
feat_tip,
502+
"side doesn't conflict, so it must still be rebased"
503+
);
504+
}
505+
444506
#[test]
445507
fn cli_apply_submit_json_outputs_op_results() {
446508
let fx = setup_with_remotes();

0 commit comments

Comments
 (0)