Skip to content

Commit 1530010

Browse files
committed
Don't pass read-file-name's result directly to git
When Magit is used with Tramp, read-file-name will return a path like /ssh:host:/path/to/file. The host part needs to be stripped before passing the path to the host's git. bf4332c fixed this issue for magit-am-apply-{patches,maildir}. This commit should take care of the remaining places that call git with an unconverted read-file-name result. Follow the approach from bf4332c of converting a path at the time it is passed to the git function rather than when it is returned by read-file-name. Note, however, that magit-file-rename is the only function from bf4332c or this commit that makes use of the full host:path, so it might make sense to add a function that wraps (magit-read-file-name-convert (read-file-name ... )). Re: #3368
1 parent bf4332c commit 1530010

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lisp/magit-diff.el

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,8 +982,10 @@ be committed."
982982
(interactive (list (read-file-name "First file: " nil nil t)
983983
(read-file-name "Second file: " nil nil t)))
984984
(magit-diff-setup nil (list "--no-index")
985-
nil (list (expand-file-name a)
986-
(expand-file-name b))))
985+
nil (list (magit-convert-filename-for-git
986+
(expand-file-name a))
987+
(magit-convert-filename-for-git
988+
(expand-file-name b)))))
987989

988990
(defvar-local magit-buffer-revision-hash nil)
989991

lisp/magit-files.el

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,15 @@ If FILE isn't tracked in Git, fallback to using `rename-file'."
352352
(newname (read-file-name (format "Rename %s to file: " file))))
353353
(list (expand-file-name file (magit-toplevel))
354354
(expand-file-name newname))))
355-
(if (magit-file-tracked-p file)
355+
(if (magit-file-tracked-p (magit-convert-filename-for-git file))
356356
(let ((oldbuf (get-file-buffer file)))
357357
(when (and oldbuf (buffer-modified-p oldbuf))
358358
(user-error "Save %s before moving it" file))
359359
(when (file-exists-p newname)
360360
(user-error "%s already exists" newname))
361-
(magit-run-git "mv" file newname)
361+
(magit-run-git "mv"
362+
(magit-convert-filename-for-git file)
363+
(magit-convert-filename-for-git newname))
362364
(when oldbuf
363365
(with-current-buffer oldbuf
364366
(let ((buffer-read-only buffer-read-only))
@@ -493,7 +495,7 @@ If DEFAULT is non-nil, use this as the default value instead of
493495
(--when-let (magit-file-at-point)
494496
(file-relative-name it))))
495497
(magit-patch-apply-arguments)))
496-
(magit-run-git "apply" args "--" file))
498+
(magit-run-git "apply" args "--" (magit-convert-filename-for-git file)))
497499

498500
(defun magit-patch-save (file &optional arg)
499501
"Write current diff into patch FILE.

0 commit comments

Comments
 (0)