Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"git-gutter+-refresh wrong type argument" when saving and opening file with Tramp over SSH #12860

Open
sweepline opened this issue Oct 25, 2019 · 8 comments

Comments

@sweepline
Copy link

Description :octocat:

Git gutter reports error with tramp on open and save

Reproduction guide 🪲

  • Start Emacs
  • open an ssh connection with tramp (e.g. SPC f f -> /ssh:host:file)
  • save file

Observed behaviour: 👀 💔
The file saves correctly but the git-gutter+-refresh reports a wrong argument error and the same error on file open (thouugh file opens correctly).

Expected behaviour: ❤️ 😄
Pretty much the same without the git-gutter error

System Info 💻

  • OS: gnu/linux
  • Emacs: 26.3
  • Spacemacs: 0.300.0
  • Spacemacs branch: develop (rev. 5fcd6e3)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: vim
  • Completion: helm
  • Layers:
(auto-completion syntax-checking helm lsp multiple-cursors
				 (shell :variables shell-default-height 30 shell-default-position 'bottom)
				 treemacs git version-control emacs-lisp markdown org
				 (rust :variables rust-backend 'lsp)
				 (python :variables python-backend 'lsp python-fill-column 100 python-formatter 'black)
				 prettier react
				 (javascript :variables javascript-import-tool 'import-js javascript-fmt-tool 'prettier javascript-lsp-linter nil node-add-modules-path t)
				 (html :variables web-fmt-tool 'prettier css-enable-lsp t scss-enable-lsp t)
				 (typescript :variables node-add-modules-path t typescript-fmt-on-save t typescript-fmt-tool 'prettier typescript-backend 'lsp typescript-lsp-linter 'eslint))
  • System configuration features: XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS GLIB NOTIFY LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS XWIDGETS LIBSYSTEMD LCMS2

Backtrace 🐾

Saving file /ssh:HOST:FILE.json...

Tramp: Checking ‘vc-registered’ for /ssh:HOST:FILE.json...done
Saving file /ssh:HOST:FILE.json...
Tramp: Encoding local file ‘/tmp/tramp.M2enP8.json’ using ‘base64-encode-region’...done
Tramp: Decoding remote file ‘/ssh:HOST:FILE.json’ using ‘base64 -d -i >%s’...done
Wrote /ssh:HOST:FILE.json
git-gutter+-refresh: Wrong type argument: arrayp, (tramp-file-name #("ssh" 0 3 (helm-ff-file t)) nil nil #("HOST" 0 3 (helm-ff-file t)) nil "/ssh:HOST:FILE.json" nil)
@loysollivier
Copy link
Contributor

Same issue here !
Found a workaround:
(remove-hook 'find-file-hook 'git-gutter+-turn-on)

@stradicat
Copy link
Contributor

stradicat commented Mar 21, 2020

The workaround doesn't work as of March 21 2020

What does work, however, is the following code snippet under (defun dotspacemacs/user-config ()):

(defun git-gutter+-remote-default-directory (dir file)
  (let* ((vec (tramp-dissect-file-name file))
          (method (tramp-file-name-method vec))
          (user (tramp-file-name-user vec))
          (domain (tramp-file-name-domain vec))
          (host (tramp-file-name-host vec))
          (port (tramp-file-name-port vec)))
     (tramp-make-tramp-file-name method user domain host port dir)))

(defun git-gutter+-remote-file-path (dir file)
  (let ((file (tramp-file-name-localname (tramp-dissect-file-name file))))
    (replace-regexp-in-string (concat "\\`" dir) "" file)))

Source: nonsequitur/git-gutter-plus#39 (comment)

Edit: it works sometimes.

@ngoonee
Copy link

ngoonee commented Apr 21, 2020

Both workarounds don't improve this behaviour for me...

@stradicat
Copy link
Contributor

You’re right @ngoonee, it’s not working now.

@datalogics-kam
Copy link

datalogics-kam commented Jun 11, 2020

Edit: it works sometimes.

I put this inside dotspacemacs/user-config, and it seems to be working for me. The patched functions would have to be added after git-gutter+ loads.

(defun dotspacemacs/user-config ()
  "Configuration for user code:
This function is called at the very end of Spacemacs startup, after layer
configuration.
Put your configuration code here, except for variables that should be set
before packages are loaded."
  ;; fixes to git-gutter+ when using tramp
  (with-eval-after-load 'git-gutter+
    ;; https://github.com/syl20bnr/spacemacs/issues/12860#issuecomment-602084919
    (defun git-gutter+-remote-default-directory (dir file)
      (let* ((vec (tramp-dissect-file-name file))
             (method (tramp-file-name-method vec))
             (user (tramp-file-name-user vec))
             (domain (tramp-file-name-domain vec))
             (host (tramp-file-name-host vec))
             (port (tramp-file-name-port vec)))
        (tramp-make-tramp-file-name method user domain host port dir)))

    (defun git-gutter+-remote-file-path (dir file)
      (let ((file (tramp-file-name-localname (tramp-dissect-file-name file))))
        (replace-regexp-in-string (concat "\\`" dir) "" file)))
    )
  )

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Aug 25, 2021
@stradicat
Copy link
Contributor

Edit: it works sometimes.

I put this inside dotspacemacs/user-config, and it seems to be working for me. The patched functions would have to be added after git-gutter+ loads.

(defun dotspacemacs/user-config ()
  "Configuration for user code:
This function is called at the very end of Spacemacs startup, after layer
configuration.
Put your configuration code here, except for variables that should be set
before packages are loaded."
  ;; fixes to git-gutter+ when using tramp
  (with-eval-after-load 'git-gutter+
    ;; https://github.com/syl20bnr/spacemacs/issues/12860#issuecomment-602084919
    (defun git-gutter+-remote-default-directory (dir file)
      (let* ((vec (tramp-dissect-file-name file))
             (method (tramp-file-name-method vec))
             (user (tramp-file-name-user vec))
             (domain (tramp-file-name-domain vec))
             (host (tramp-file-name-host vec))
             (port (tramp-file-name-port vec)))
        (tramp-make-tramp-file-name method user domain host port dir)))

    (defun git-gutter+-remote-file-path (dir file)
      (let ((file (tramp-file-name-localname (tramp-dissect-file-name file))))
        (replace-regexp-in-string (concat "\\`" dir) "" file)))
    )
  )

This definitely did the trick!

Perhaps your proposal should be integrated into Spacemacs 😄

@github-actions github-actions bot removed the stale marked as a stale issue/pr (usually by a bot) label Sep 27, 2021
@perezandrew477
Copy link

Thanks @datalogics-kam! This worked for me too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants