diff --git a/my-repo-pins-tests.el b/my-repo-pins-tests.el index b1ca2c9..be4c5ca 100644 --- a/my-repo-pins-tests.el +++ b/my-repo-pins-tests.el @@ -335,6 +335,17 @@ it'll get deleted before the end of the test." (should (not (file-exists-p (concat tmpdir "/destination")))) (delete-directory tmpdir t) (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 ;;;;;;;;;;;;;;;;; diff --git a/my-repo-pins.el b/my-repo-pins.el index e2e7092..d34fe06 100644 --- a/my-repo-pins.el +++ b/my-repo-pins.el @@ -109,6 +109,18 @@ Errors out if we can't find it." git-from-bin-path (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) "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*")) (git-window nil) (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 (process _event) (let ((exit-code (process-exit-status process))) @@ -136,6 +152,7 @@ Returns the git PROCESS object." :name "my-repo-pins-git-subprocess" :buffer git-buffer :command (seq-concatenate 'list `(,(my-repo-pins--git-path)) args) + :filter git-filter :sentinel git-sentinel) (set-buffer current-buffer))))