diff options
| -rw-r--r-- | lisp/magit-apply.el | 3 | ||||
| -rw-r--r-- | lisp/magit-diff.el | 8 |
2 files changed, 10 insertions, 1 deletions
diff --git a/lisp/magit-apply.el b/lisp/magit-apply.el index 3f6f5bd..fcf119f 100644 --- a/lisp/magit-apply.el +++ b/lisp/magit-apply.el @@ -220,6 +220,7 @@ adjusted as \"@@ -10,6 +10,7 @@\" and \"@@ -18,6 +19,7 @@\"." (command (if (and command (string-match "^magit-\\([^-]+\\)" command)) (match-string 1 command) "apply")) + (context (magit-diff-get-context)) (ignore-context (magit-diff-ignore-any-space-p))) (unless (magit-diff-context-p) (user-error "Not enough context to apply patch. Increase the context")) @@ -230,7 +231,7 @@ adjusted as \"@@ -10,6 +10,7 @@\" and \"@@ -18,6 +19,7 @@\"." (let ((magit-inhibit-refresh t)) (magit-run-git-with-input "apply" args "-p0" - (and ignore-context "-C0") + (if ignore-context "-C0" (format "-C%s" context)) "--ignore-space-change" "-"))) (unless magit-inhibit-refresh (when magit-wip-after-apply-mode diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el index 58bd8c7..3a9faaf 100644 --- a/lisp/magit-diff.el +++ b/lisp/magit-diff.el @@ -1549,6 +1549,14 @@ instead." (setq magit-buffer-diff-args val)) (magit-refresh)) +(defun magit-diff-get-context () + (string-to-number + (or (seq-some (##and (string-match "\\`-U\\([0-9]+\\)?\\'" %) + (match-string 1 %)) + magit-buffer-diff-args) + (magit-get "diff.context") + "3"))) + (defun magit-diff-context-p () (if-let ((arg (seq-find (##string-match "^-U\\([0-9]+\\)$" %) magit-buffer-diff-args))) |
