rhysd / committia.vim

A Vim plugin for more pleasant editing on commit messages
MIT License
731 stars 30 forks source link

Error after updating commitia #32

Closed ffesseler closed 7 years ago

ffesseler commented 7 years ago

commitia worked fine until I updated the plugin yesterday. When I type "git commit", I get an error :

Error detected while processing function committia#open[14]..<SNR>81_open_multicolumn[10]..<SNR>81_open_status_window[1]..<SNR>81_open_window[1]..committia#git#status:
line   18:
E605: Exception not caught: committia: git: Failed to execute status command: fatal: This operation must be run in a work tree^@
Error detected while processing function committia#open:
line   14:
E171: Missing :endif

This seems related to the changes introduced with #31 .

rhysd commented 7 years ago

I'm always using HEAD of committia.vim but I've not seen this problem. Could you provide how to reproduce? And I need to know your environment (version of git and Vim, OS)

ffesseler commented 7 years ago

I'm using git version 2.10.1 (Apple Git-78)

I'll try to find how to reproduce it. Right now, it happens on a private git repo.

rhysd commented 7 years ago

git status command looks failed.

diff --git a/autoload/committia/git.vim b/autoload/committia/git.vim
index 0f92c53..19dce13 100644
--- a/autoload/committia/git.vim
+++ b/autoload/committia/git.vim
@@ -62,7 +62,9 @@ function! s:search_git_dir_and_work_tree() abort
 endfunction

 function! s:execute_git(cmd, git_dir, work_tree) abort
-    return s:system(printf('%s --git-dir="%s" --work-tree="%s" %s', g:committia#git#cmd, a:git_dir, a:work_tree, a:cmd))
+    let tmp = printf('%s --git-dir="%s" --work-tree="%s" %s', g:committia#git#cmd, a:git_dir, a:work_tree, a:cmd)
+    echom tmp
+    return s:system(tmp)
 endfunction

 function! s:ensure_index_file(git_dir) abort

With this diff, you can see actual command which was executed with :message. Could you try this and try the same command in command line? Does it fail also?

EDIT: Sorry, diff was wrong (fixed).

rhysd commented 7 years ago

If your repository is public, I think I can also try the situation.

rhysd commented 7 years ago

ping @anekos: if you notice something, please help me to fix this.

ffesseler commented 7 years ago

Command executed :

git --git-dir="/Users/ffesseler/bla/.git" --work-tree="/Users/ffesseler/bla^@" diff -u --cached --no-color --no-ext-diff

It works fine when using it in the command line. Here is the output :

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
modified: server/client-html/src/main/resources/client-html-src/src/app/components/editors/noteEditor/noteEditor.js
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
@ noteEditor.js:1 @
//
import { NoteToolSet } from 'domain/model';
import { toHexa } from 'utils/color';
import { NotePaddings, NoteExtraTextPadding, NoteFont, TextCommonStyle } from 'domain/constants';
rhysd commented 7 years ago
/Users/ffesseler/bla^@

Ah, it looks that NL remains in work tree directory path... I'll take a look.

ffesseler commented 7 years ago

Wait, this is the command that actually fails :

git --git-dir="/Users/ffesseler/bla/.git" --work-tree="/Users/ffesseler/bla^@" -c color.status=false status -b

fatal: This operation must be run in a work tree

rhysd commented 7 years ago

Thanks.

rhysd commented 7 years ago

I still can't understand what happens...

Could you try below diff? Is something output? If so, please let me see what was output.

diff --git a/autoload/committia/git.vim b/autoload/committia/git.vim
index 0f92c53..c482c57 100644
--- a/autoload/committia/git.vim
+++ b/autoload/committia/git.vim
@@ -43,6 +43,7 @@ function! s:search_git_dir_and_work_tree() abort
             let work_tree = fnamemodify(readfile(git_dir . '/gitdir')[0], ':h')
         else
             let work_tree = s:extract_first_line(s:system(printf('%s --git-dir="%s" rev-parse --show-toplevel', g:committia#git#cmd, git_dir)))
+            echom work_tree
         endif
         return [git_dir, work_tree]
     endif
ffesseler commented 7 years ago

Here is the output

/Users/ffesseler/bla^@
/Users/ffesseler/bla^@
rhysd commented 7 years ago

The ^@ represents newline. So, actual command is:

git --git-dir="/Users/ffesseler/bla/.git" --work-tree="/Users/ffesseler/bla
" -c color.status=false status -b

I think it also fails in command line (if you try, please enter new line after ctrl+v in terminal)

rhysd commented 7 years ago

@ffesseler Thank you. So I guess

s:extract_first_line(s:system(printf('%s --git-dir="%s" rev-parse --show-toplevel', g:committia#git#cmd, git_dir)))

returns the wrong work tree path.

ffesseler commented 7 years ago

Indeed: git --git-dir="/Users/ffesseler/bla/.git" --work-tree="/Users/ffesseler/bla" -c color.status=false status -b works in command line

git --git-dir="/Users/ffesseler/bla/.git" --work-tree="/Users/ffesseler/bla^@" -c color.status=false status -b

does not.

rhysd commented 7 years ago

Could you tell me the output of

:echo &magic

set nomagic may change how to interpret regex in match() in s:extract_first_line().

rhysd commented 7 years ago

@ffesseler Thank you for clarifying it. The newline ^@ looks root cause of this bug.

ffesseler commented 7 years ago

:echo &magic outputs 1

rhysd commented 7 years ago

Thanks. So nomagic is not related to this problem.

I submitted a commit 08b671a . Your system is macOS. So it may not be related to this problem, but could you try the latest?

rhysd commented 7 years ago

And if you can, please tell me the output of below command:

If you don't use vimproc.vim:

:echom string(system("git --git-dir='/Users/ffesseler/bla/.git' rev-parse --show-toplevel"))

If you use vimproc.vim:

:echom string(vimproc#system("git --git-dir='/Users/ffesseler/bla/.git' rev-parse --show-toplevel"))
ffesseler commented 7 years ago

Same issue with the last version.

:echom string(system("git --git-dir='/Users/ffesseler/bla/.git' rev-parse --show-toplevel"))

outputs : '/Users/ffesseler/bla^@'

rhysd commented 7 years ago

Thank you.

Hmm... so the problem is why s:extract_first_line does not extract first line.

rhysd commented 7 years ago

Does 3be483f fix this problem?

ffesseler commented 7 years ago

Yes ! Works fine now :)

rhysd commented 7 years ago

I found that [^\n]\+ should have been ^[^\n]\+, but 3be483f also works. Thank you for your cooperation. It was very helpful 👍

ffesseler commented 7 years ago

Thanks to you for fixing this very quickly and for providing me some tips to help debugging !