[PATCH b4 v2 4/6] review-tui: run take->merge abort in the target branch's worktree
Christian Brauner <[email protected]> Tue, 23 Jun 2026 22:34:20 +0200
| Newsgroups | org.kernel.linux.tools |
|---|---|
| Message-ID | <20260623-20260623-review-tui-take-am-worktree-v2-4-2cbbab5d5441@kernel.org> |
take->merge applies a series in whichever worktree holds the target branch.
git_run_command() addresses that worktree with --git-dir when it is the
primary worktree (its .git is a directory), which sets the git dir but not
the work tree -- git then takes the work tree from the process cwd. The
production merge sidesteps this by running git -C merge_dir, but two calls
on the same path do not pass rundir and so run in b4's cwd instead: the
git merge --abort on the failure path, and the pytest-only non-interactive
merge.
When review is driven from a different worktree than the target's -- the
case _take_worktree() exists for -- and the target lives in the primary
worktree, a conflicting take leaves the conflict in merge_dir (written
there via -C) but then aborts against the wrong work tree. git merge
--abort reports success and clears MERGE_HEAD, yet the conflict markers
stay in the target worktree and b4's own checkout is rewritten from the
target's index: the target is left dirty and an unrelated worktree is
clobbered, both silently.
Pass rundir=merge_dir to both calls so they run in the target worktree,
matching the production git -C merge_dir and take->am's git-am, which
already anchors with rundir=am_dir.
Fixes: db9a629c3e95 ("review-tui: run take->merge in the target branch's worktree")
Signed-off-by: Christian Brauner (Amutable) <[email protected]>
---
src/b4/review_tui/_tracking_app.py | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/b4/review_tui/_tracking_app.py b/src/b4/review_tui/_tracking_app.py
index a16f845..ef61e0e 100644
--- a/src/b4/review_tui/_tracking_app.py
+++ b/src/b4/review_tui/_tracking_app.py
@@ -2825,7 +2825,9 @@ class TrackingApp(LoreNodeShutdownMixin, CheckRunnerMixin, App[Optional[str]]):
'--no-edit',
'FETCH_HEAD',
] + mergeflags
- ecode, out = b4.git_run_command(merge_dir, mergeargs, logstderr=True)
+ ecode, out = b4.git_run_command(
+ merge_dir, mergeargs, logstderr=True, rundir=merge_dir
+ )
else:
# Run git directly with an inherited tty (under the caller's
# suspend()) so git can open the editor, like _suspend_to_shell.
@@ -2853,7 +2855,9 @@ class TrackingApp(LoreNodeShutdownMixin, CheckRunnerMixin, App[Optional[str]]):
'Merge failed%s', f': {out.strip()}' if out.strip() else ''
)
logger.critical('Aborting merge...')
- b4.git_run_command(merge_dir, ['merge', '--abort'], logstderr=True)
+ b4.git_run_command(
+ merge_dir, ['merge', '--abort'], logstderr=True, rundir=merge_dir
+ )
_wait_for_enter()
return
--
2.53.0