mirror of
https://github.com/NinjaTrappeur/my-repo-pins.git
synced 2024-06-01 19:14:07 +02:00
[bugfix] Reformat git command output newlines
The git stdout newline separator is customizable. Sadly for us, it seems like it uses a carriage return (CR) separator by default. Emacs won't treat CR as a newline, it needs a CR;LF. We can configure git to use CR;LF, that being said, we don't want to modify the user's git configuration here. Adding a process filter to rewrite the newline separators on the go.
This commit is contained in:
parent
4866b1d1ef
commit
98e76c2d17
|
@ -335,6 +335,17 @@ it'll get deleted before the end of the test."
|
||||||
(should (not (file-exists-p (concat tmpdir "/destination"))))
|
(should (not (file-exists-p (concat tmpdir "/destination"))))
|
||||||
(delete-directory tmpdir t)
|
(delete-directory tmpdir t)
|
||||||
(funcall done)))))
|
(funcall done)))))
|
||||||
|
;; Git filter Tests
|
||||||
|
;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(ert-deftest my-repo-pins--test-call-git-in-dir-process-filter ()
|
||||||
|
"Test the ‘my-repo-pins--test-call-git-in-dir-process-filter’ filter."
|
||||||
|
(should (equal (my-repo-pins--call-git-in-dir-process-filter (format "hello%cworld" 13)) "hello\nworld"))
|
||||||
|
(should (equal (my-repo-pins--call-git-in-dir-process-filter "hello\nworld") "hello\nworld"))
|
||||||
|
(should (equal (my-repo-pins--call-git-in-dir-process-filter "hello\rworld\ranother\rline") "hello\nworld\nanother\nline"))
|
||||||
|
(should (equal (my-repo-pins--call-git-in-dir-process-filter "hello\nworld\nanother\nline") "hello\nworld\nanother\nline"))
|
||||||
|
)
|
||||||
|
|
||||||
;; Test Fetchers
|
;; Test Fetchers
|
||||||
;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
|
|
@ -109,6 +109,18 @@ Errors out if we can't find it."
|
||||||
git-from-bin-path
|
git-from-bin-path
|
||||||
(user-error "Can't find git. Is my-repo-pins-git-bin correctly set?")))))
|
(user-error "Can't find git. Is my-repo-pins-git-bin correctly set?")))))
|
||||||
|
|
||||||
|
(defun my-repo-pins--call-git-in-dir-process-filter (str)
|
||||||
|
"Filtering the git output for ‘my-repo-pins--call-git-in-dir’ call.
|
||||||
|
|
||||||
|
By default, git seems to be terminating its stdout/stderr lines using
|
||||||
|
the CR; sequence instead of the traditional CR;LF; unix sequence.
|
||||||
|
|
||||||
|
This filter tries to detect these isolated CR sequences and convert
|
||||||
|
them in a CR;LF sequence.
|
||||||
|
|
||||||
|
STR being the string we have to process."
|
||||||
|
(replace-regexp-in-string "\r" "\n" str))
|
||||||
|
|
||||||
(defun my-repo-pins--call-git-in-dir (dir &optional callback &rest args)
|
(defun my-repo-pins--call-git-in-dir (dir &optional callback &rest args)
|
||||||
"Call the git binary as pointed by ‘my-repo-pins-git-bin’ in DIR with ARGS.
|
"Call the git binary as pointed by ‘my-repo-pins-git-bin’ in DIR with ARGS.
|
||||||
|
|
||||||
|
@ -120,6 +132,10 @@ Returns the git PROCESS object."
|
||||||
(let* ((git-buffer (get-buffer-create "*my repo pins git log*"))
|
(let* ((git-buffer (get-buffer-create "*my repo pins git log*"))
|
||||||
(git-window nil)
|
(git-window nil)
|
||||||
(current-buffer (current-buffer))
|
(current-buffer (current-buffer))
|
||||||
|
(git-filter (lambda
|
||||||
|
(proc str)
|
||||||
|
(with-current-buffer (process-buffer proc)
|
||||||
|
(insert (my-repo-pins--call-git-in-dir-process-filter str)))))
|
||||||
(git-sentinel (lambda
|
(git-sentinel (lambda
|
||||||
(process _event)
|
(process _event)
|
||||||
(let ((exit-code (process-exit-status process)))
|
(let ((exit-code (process-exit-status process)))
|
||||||
|
@ -136,6 +152,7 @@ Returns the git PROCESS object."
|
||||||
:name "my-repo-pins-git-subprocess"
|
:name "my-repo-pins-git-subprocess"
|
||||||
:buffer git-buffer
|
:buffer git-buffer
|
||||||
:command (seq-concatenate 'list `(,(my-repo-pins--git-path)) args)
|
:command (seq-concatenate 'list `(,(my-repo-pins--git-path)) args)
|
||||||
|
:filter git-filter
|
||||||
:sentinel git-sentinel)
|
:sentinel git-sentinel)
|
||||||
(set-buffer current-buffer))))
|
(set-buffer current-buffer))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue