Skip to content

Commit

Permalink
magit-bisect-run: Restore checks for flipped revs and dirty tree
Browse files Browse the repository at this point in the history
As of Magit v2.90.0, magit-bisect-start aborts if the revisions are
flipped or there are uncommitted changes.  magit-bisect-run shared
those guards at the time because it used magit-bisect-start
underneath, but f592e36 (magit-bisect-run: Don't start bisect
asynchronously, 2021-06-20) moved away from magit-bisect-start,
unintentionally losing the checks.

Restore the checks by extracting them to a shared helper.

Closes magit#5070.
  • Loading branch information
kyleam committed Dec 29, 2023
1 parent c7ab693 commit faa1907
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions docs/RelNotes/4.0.0.org
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ f9ae2a6306 #4620 magit-blame--make-highlight-overlay: Add only to intended line
incorrectly repeated already applied patches in the list of
remaining patches. #5024

- ~magit-bisect-run~ is supposed to abort if there are uncommitted
changes or if the revisions are flipped (like ~magit-bisect-start~
does), but these checks were unintentionally dropped in Magit
v3.1.0. #5070

10b5407131 magit-diff-highlight-list: Ensure delayed highlighting takes place
b32521d543 magit-ediff-read-files: Handle renames in one-file logs
94aca04dc8 magit-module-section: Use correct keymap
Expand Down
22 changes: 13 additions & 9 deletions lisp/magit-bisect.el
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,7 @@ other actions from the bisect transient command (\
(interactive (if (magit-bisect-in-progress-p)
(user-error "Already bisecting")
(magit-bisect-start-read-args)))
(unless (magit-rev-ancestor-p good bad)
(user-error
"The %s revision (%s) has to be an ancestor of the %s one (%s)"
(or (transient-arg-value "--term-old=" args) "good")
good
(or (transient-arg-value "--term-new=" args) "bad")
bad))
(when (magit-anything-modified-p)
(user-error "Cannot bisect with uncommitted changes"))
(magit-bisect-start--assert bad good args)
(magit-repository-local-set 'bisect--first-parent
(transient-arg-value "--first-parent" args))
(magit-git-bisect "start" (list args bad good) t))
Expand All @@ -130,6 +122,17 @@ other actions from the bisect transient command (\
bad)
args)))

(defun magit-bisect-start--assert (bad good args)
(unless (magit-rev-ancestor-p good bad)
(user-error
"The %s revision (%s) has to be an ancestor of the %s one (%s)"
(or (transient-arg-value "--term-old=" args) "good")
good
(or (transient-arg-value "--term-new=" args) "bad")
bad))
(when (magit-anything-modified-p)
(user-error "Cannot bisect with uncommitted changes")))

;;;###autoload
(defun magit-bisect-reset ()
"After bisecting, cleanup bisection state and return to original `HEAD'."
Expand Down Expand Up @@ -197,6 +200,7 @@ bisect run'."
(magit-bisect-start-read-args))))
(cons (read-shell-command "Bisect shell command: ") args)))
(when (and bad good)
(magit-bisect-start--assert bad good args)
;; Avoid `magit-git-bisect' because it's asynchronous, but the
;; next `git bisect run' call requires the bisect to be started.
(magit-with-toplevel
Expand Down

0 comments on commit faa1907

Please sign in to comment.