branch: elpa/git-commit commit f9a15cb349b24ce705cae3dde646a1e027dc54d5 Author: Kyle Meyer <k...@kyleam.com> Commit: Kyle Meyer <k...@kyleam.com>
magit-discard-files: Account for 'renamed on both sides' conflicts Merging two lines that both renamed a file leads to a conflict like this: DD f AU f-rename UA f-rename-side In the status buffer, that shows up as three staged entries: Staged changes (3) unmerged f (both deleted) unmerged f-rename (added by us) unmerged f-rename-side (added by them) For conflicts in the staged section, calling magit-discard to trigger magit-discard-files--resolve/magit-checkout-stage is useful for letting the caller choose a side's variant. However, that doesn't work for the entries above: * On the first entry, magit-discard-files--delete is called rather than magit-discard-files--resolve/magit-checkout-stage, and it fails trying to delete a working tree file that isn't there. * On the second and third entries, calling magit-discard does go down the magit-discard-files--resolve/magit-checkout-stage path. That works as expected when choosing the side with the file in its tree (e.g., choosing "ours" for f-rename above). However, choosing the other side leads to the 'git checkout --ours/theirs' call failing because the file doesn't exist on that side. Fix magit-discard on the first entry by sending DD entries to magit-discard-files--resolve rather than magit-discard-files--delete. Asking the caller to choose a side is a bit odd because either side is equivalent, but it's probably an uncommon enough case that it's not worth adding dedicated handling for it. Fix magit-discard on the second and third entries by teaching magit-checkout-stage go down the 'git rm' path if it sees UA/AU for the side the does not have the file in its tree. Fixes #4225. --- docs/RelNotes/3.4.0.org | 3 +++ lisp/magit-apply.el | 3 ++- lisp/magit-merge.el | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/RelNotes/3.4.0.org b/docs/RelNotes/3.4.0.org index a46e266fc4..cc0c0aaa19 100644 --- a/docs/RelNotes/3.4.0.org +++ b/docs/RelNotes/3.4.0.org @@ -45,3 +45,6 @@ - For Helm users, calling ~magit-stash-drop~ on the "Stashes" section has been broken since v3.0.0. #4571 + +- ~magit-discard~ didn't properly handle conflicts resulting from a + file being renamed on both sides. #4225 diff --git a/lisp/magit-apply.el b/lisp/magit-apply.el index 3edae33c08..2ca43e0aef 100644 --- a/lisp/magit-apply.el +++ b/lisp/magit-apply.el @@ -546,7 +546,8 @@ of a side, then keep that side without prompting." (`(?Z) (dolist (f (magit-untracked-files nil file)) (push f delete))) ((or `(?Z ?? ??) `(?Z ?! ?!)) (push file delete)) - ((or `(?Z ?D ? ) `(,_ ?D ?D)) (push file delete)) + (`(?Z ?D ? ) (push file delete)) + (`(,_ ?D ?D) (push file resolve)) ((or `(,_ ?U ,_) `(,_ ,_ ?U)) (push file resolve)) (`(,_ ?A ?A) (push file resolve)) (`(?X ?M ,(or ? ?M ?D)) (push section discard)) diff --git a/lisp/magit-merge.el b/lisp/magit-merge.el index 470cac96a1..d153c2755a 100644 --- a/lisp/magit-merge.el +++ b/lisp/magit-merge.el @@ -255,7 +255,9 @@ then also remove the respective remote branch." (user-error "Quit"))))) (pcase (cons arg (cddr (car (magit-file-status file)))) ((or `("--ours" ?D ,_) - `("--theirs" ,_ ?D)) + `("--ours" ?U ?A) + `("--theirs" ,_ ?D) + `("--theirs" ?A ?U)) (magit-run-git "rm" "--" file)) (_ (if (equal arg "--merge") ;; This fails if the file was deleted on one