michal-h21 / vimwiki-sync

Automaticaly synchronize vimwiki at startup and exit using git
98 stars 25 forks source link

Added, but not committed #14

Open nnzv opened 2 years ago

nnzv commented 2 years ago

Reproduce

  1. Open a wiki file
  2. Edit that file
  3. :wq

Expected behavior

Commit the added file on nvim exit.

Neovim Information

% nvim -v
NVIM v0.7.2
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/x86_64-pc-linux-gnu-gcc -O2 -pipe -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -Wimplicit-fallthrough -Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=malloc -Wsuggest-attribute=cold -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/var/tmp/portage/app-editors/neovim-0.7.2/work/neovim-0.7.2_build/config -I/var/tmp/portage/app-editors/neovim-0.7.2/work/neovim-0.7.2/src -I/usr/include -I/var/tmp/portage/app-editors/neovim-0.7.2/work/neovim-0.7.2_build/src/nvim/auto -I/var/tmp/portage/app-editors/neovim-0.7.2/work/neovim-0.7.2_build/include
Compiled by portage@localhost

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "/etc/vim/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Additional Information

" ~/.config/nvim/init.vim
set 
  \ nu 
  \ nuw=5
  \ tgc 
  \ et 
  \ ea 
  \ noswf
  \ nohls 
  \ lz
  \ nowb
  \ smc=180
  \ wig=*.o,*.pyc,*pycache*
  \ nosmd
  \ nowrap
  \ vif=NONE
  \ ls=0
  \ nobk 
  \ noru
  \ bg=dark
  \ cb=unnamedplus
  \ ut=1000
  \ so=10
  \ shm=aIF
  \ ts=4
  \ sts=4
  \ sw=4
  \ fcs=eo  \ ut=1000
  \ so=10
  \ shm=aIF
  \ ts=4
  \ sts=4
  \ sw=4
  \ fcs=eob:\ ,

let g:vimwiki_list = [{
    \ 'path': '/home/nzv/.config/nvim/wiki',
    \ 'template_path': '~/.config/nvim/wiki/tpl',
    \ 'template_default': 'default',
    \ 'syntax': 'markdown',
    \ 'ext': '.md',
    \ 'path_html': '~/.cache/vimwiki_html',
    \ 'template_ext': '.tpl'
\}]

au FileType vimwiki 
    \ setl spell wrap nonu ch=2

" Easy buffer navigation
nn <C-J> <C-W><C-J>
nn <C-K> <C-W><C-K>
nn <C-L> <C-W><C-L>
nn <C-H> <C-W><C-H>

" Remove arrow keys in some modes
for key in [
    \  '<Down> <Nop>',
    \  '<Left> <Nop>',
    \ '<Right> <Nop>',
    \    '<Up> <Nop>',
\]
    for mod in ['no', 'no!', 'vn', 'ino', 'cno']
        exe mod key
    endfor
endfor

for p in [
    \ '2html_plugin',
    \ 'getscript',
    \ 'getscriptPlugin',
    \ 'gzip',
    \ 'logipat',
    \ 'matchparen',
    \ 'netrw',
    \ 'netrwFileHandlers',
    \ 'netrwPlugin',
    \ 'netrwSettings',
    \ 'rrhelper',
    \ 'spellfile_plugin',
    \ 'sql_completion',
    \ 'syntax_completion',
    \ 'tar',
    \ 'tarPlugin',
    \ 'vimball',
    \ 'vimballPlugin',
    \ 'zip',
    \ 'zipPlugin',
    \ 'vimsyn_embed',
\]
    exe 'let g:loaded_' . p . '= 1'
endfor

call plug#begin()
    Plug 'hashivim/vim-terraform'
    Plug 'weakish/rcshell.vim'
    Plug 'tpope/vim-commentary'
    Plug 'vimwiki/vimwiki'
    Plug 'tpope/vim-fugitive'
    Plug 'michal-h21/vimwiki-sync'
call plug#end()
syn enable | colo ocean

# cwd: /home/nzv/.config/nvim/wiki
% git remote show origin
* remote origin
  Fetch URL: git@github.com:nnzv/wiki.git
  Push  URL: git@github.com:nnzv/wiki.git
  HEAD branch: main
  Remote branch:
    main tracked
  Local ref configured for 'git push':
    main pushes to main (up to date)
michal-h21 commented 2 years ago

I cannot reproduce this issue with your config file. Files are committed without problems.

nnzv commented 2 years ago

I cannot reproduce this issue with your config file. Files are committed without problems.

In advance, thanks for the support. I've tried some things (e.g, debugging):

Nvim start

% nvim -V20 ~/.config/nvim/wiki/index.md
...
...
line 4:   let value = get(getbufvar(buffer, ''), 'vimwiki_'.a:key, '/\/\')
line 5:   if type(value) != 1 || value !=# '/\/\'
line 6:     return value
function <SNR>17_setup_buffer_enter[3]..vimwiki#vars#get_bufferlocal returning #0
continuing in function <SNR>17_setup_buffer_enter
line 4:     return
line 5:   endif
line 6:
line 7:   call s:set_global_options()
calling function <SNR>17_setup_buffer_enter[7]..<SNR>17_set_global_options()
line 1:   let s:vimwiki_autowriteall_saved = &autowriteall
line 2:   let &autowriteall = vimwiki#vars#get_global('autowriteall')
calling function <SNR>17_setup_buffer_enter[7]..<SNR>17_set_global_options[2]..vimwiki#vars#get_global('autowriteall')
line 1:   return g:vimwiki_global_vars[a:key]
function <SNR>17_setup_buffer_enter[7]..<SNR>17_set_global_options[2]..vimwiki#vars#get_global returning #1
continuing in function <SNR>17_setup_buffer_enter[7]..<SNR>17_set_global_options
line 3:
line 4:   if !empty(vimwiki#vars#get_global('menu'))
calling function <SNR>17_setup_buffer_enter[7]..<SNR>17_set_global_options[4]..vimwiki#vars#get_global('menu')
line 1:   return g:vimwiki_global_vars[a:key]
function <SNR>17_setup_buffer_enter[7]..<SNR>17_set_global_options[4]..vimwiki#vars#get_global returning 'Vimwiki'
continuing in function <SNR>17_setup_buffer_enter[7]..<SNR>17_set_global_options
line 5:     exe 'nmenu enable '.vimwiki#vars#get_global('menu').'.Table'
calling function <SNR>17_setup_buffer_enter[7]..<SNR>17_set_global_options[5]..vimwiki#vars#get_global('menu')
line 1:   return g:vimwiki_global_vars[a:key]
function <SNR>17_setup_buffer_enter[7]..<SNR>17_set_global_options[5]..vimwiki#vars#get_global returning 'Vimwiki'
continuing in function <SNR>17_setup_buffer_enter[7]..<SNR>17_set_global_options
line 5: nmenu enable Vimwiki.Table
line 6:   endif
function <SNR>17_setup_buffer_enter[7]..<SNR>17_set_global_options returning #0
continuing in function <SNR>17_setup_buffer_enter
function <SNR>17_setup_buffer_enter returning #0
continuing in BufEnter Autocommands for "*.md"
Executing BufEnter Autocommands for "*"
autocommand call <sid>pull_changes()
Executing: call <sid>pull_changes()
calling function <SNR>51_pull_changes()
line 1:     if g:zettel_synced==0
line 2:       echom "[vimwiki sync] pulling changes"
[vimwiki sync] pulling changes
line 3:       let g:zettel_synced = 1
line 4:       if has("nvim")
line 5:         let gitjob = jobstart("git -C " . g:zettel_dir . " pull origin " . g:vimwiki_sync_branch, {"exit_cb": "My_exit_cb", "close_cb": "My_close_cb"})
line 6:         if g:sync_taskwarrior==1
line 7:           let taskjob = jobstart("task sync")
line 8:         endif
line 9:       else
line 10:         let gitjob = job_start("git -C " . g:zettel_dir . " pull origin " . g:vimwiki_sync_branch, {"exit_cb": "My_exit_cb", "close_cb": "My_close_cb"})
line 11:         if g:sync_taskwarrior==1
line 12:           let taskjob = job_start("task sync")
line 13:         endif
line 14:       endif
line 15:     endif
function <SNR>51_pull_changes returning #0
continuing in BufEnter Autocommands for "*"
Executing VimEnter Autocommands for "*"
Press ENTER or type command to continue
autocommand call <sid>pull_changes()
Press ENTER or type command to continue
Executing: call <sid>pull_changes()
calling function <SNR>51_pull_changes()
line 1:     if g:zettel_synced==0
line 2:       echom "[vimwiki sync] pulling changes"
line 3:       let g:zettel_synced = 1
line 4:       if has("nvim")
line 5:         let gitjob = jobstart("git -C " . g:zettel_dir . " pull origin " . g:vimwiki_sync_branch, {"exit_cb": "My_exit_cb", "close_cb": "My_close_cb"})
line 6:         if g:sync_taskwarrior==1
line 7:           let taskjob = jobstart("task sync")
line 8:         endif
line 9:       else
line 10:         let gitjob = job_start("git -C " . g:zettel_dir . " pull origin " . g:vimwiki_sync_branch, {"exit_cb": "My_exit_cb", "close_cb": "My_close_cb"})
line 11:         if g:sync_taskwarrior==1
line 12:           let taskjob = job_start("task sync")
line 13:         endif
line 14:       endif
line 15:     endif
function <SNR>51_pull_changes returning #0
continuing in VimEnter Autocommands for "*"

Nvim Exit

:q
Executing: q
Executing VimLeave Autocommands for "*"
autocommand call <sid>git_action("git -C " . g:zettel_dir . " push origin " . g:vimwiki_sync_branch)
Executing: call <sid>git_action("git -C " . g:zettel_dir . " push origin " . g:vimwiki_sync_branch)
calling function <SNR>51_git_action('git -C /home/nzv/.config/nvim/wiki/ push origin HEAD')
line 1:     execute ':silent !' . a:action
line 1: :silent !git -C /home/nzv/.config/nvim/wiki/ push origin HEAD
michal-h21 commented 2 years ago

What is strange is that git add and git commit are executed in the same command, executed on every file write in Vimwiki:

au! BufWritePost * call <sid>git_action("git -C " . g:zettel_dir . " add . ; git -C " . g:zettel_dir . " commit -m \"" . strftime(g:vimwiki_sync_commit_message) . "\"") 

So maybe git add fails, and git commit isn't executed?

nnzv commented 2 years ago

What is strange is that git add and git commit are executed in the same command [...]

Shouldn't it do? As far as I'm concerned, that's implemented on vimwiki-sync.

So maybe git add fails, and git commit isn't executed?

Certainly not, modified files were added successful. BTW, Nowadays, I use gpg to commit.

michal-h21 commented 2 years ago

Shouldn't it do? As far as I'm concerned, that's implemented on vimwiki-sync.

I meant that it is strange that your files get added, but not committed, as these two commands should run consecutively.

Does your log contain info for the BufWritePost autocommands?