lambdalisue / vim-gita

[Obsolete] An awesome git handling plugin for Vim
Other
226 stars 8 forks source link

Error on git-worktree repository #102

Closed ichizok closed 8 years ago

ichizok commented 8 years ago

Summary (required)

On git-worktree repository, Gita commit and Gita status cause error.

Behavior (required)

:Gita status
Error detected while processing function gita#content#autocmd[7]..gita#content#status#autocmd[2]..<SNR>242_on_BufReadCmd[16]..gita#content#status#redraw[2]..<SNR>242_get
_prologue:
line    4:
E716: Key not present in Dictionary: remote)
E116: Invalid arguments for function empty(remote.remote)
E15: Invalid expression: !empty(remote.remote)

Minimal vimrc (required)

" Start Vim with '-u {scriptfile}' option like 'vim -u ~/.vimrc.min'
if has('vim_starting')
  set nocompatible
  " Add vim-gita repository to the runtimepath
  set runtimepath+=~/.vim/bundle/vim-gita
endif
" Add minimum requirements below

Procedure (required)

$ git init testdir
$ cd testdir
$ echo hello > testfile
$ git add testfile
$ git commit -m'commit'
$ git worktree -b spike ../testdir.spike master
$ cd ../testdir.spike
$ vim -Nu vimrc testfile
:Gita status

Environment

Write your environment informations as many as possible.

On git-worktree repository, s:GitInfo.get_remote_branch() returns { 'name': '', 'hash': '', 'url': '' }, lack of remote key.

https://github.com/lambdalisue/vim-gita/blob/master/autoload/vital/__gita__/Git/Info.vim#L228 https://github.com/lambdalisue/vim-gita/blob/master/autoload/gita/statusline.vim#L238

here checking remote.remote directly, thus, causes error.

https://github.com/lambdalisue/vim-gita/blob/master/autoload/gita/content/commit.vim#L99

lambdalisue commented 8 years ago

Confirmed thanks! https://github.com/lambdalisue/vim-gita/commit/14b6174e32a11b9f74995e6b744cc7dcfe71c8c7 would fix this

ichizok commented 8 years ago

Thank you for fix quickly :+1:

ichizok commented 8 years ago

There is a case main repository has remote branch.

$ git clone https://github.com/lambdalisue/vim-gita
$ cd vim-gita
$ git worktree add -b develop ../vim-gita_develop origin/develop
$ cd ../vim-gita_develop
$ vim
:Gita status
status of vim-gita_develop/develop | Press ? to show help or <Tab> to select action

missing remote.

desirable:

:Gita status
status of vim-gita_develop/develop <> origin/develop | Press ? to show help or <Tab> to select action
lambdalisue commented 8 years ago

Thanks. Hum... it seems the implementation requires to be a bit tricky.

<repository>/worktree-test/.git becomes a file and the content is

gitdir: <root>/vim-gita/.git/worktrees/worktree-test

And vim-gita/.git directory contains

- .git/                            
 |+ branches/                      
 |+ hooks/                         
 |+ info/                          
 |+ logs/                          
 |+ objects/                       
 |+ refs/                          
 |- worktrees/                     
  |- worktree-test/                
   |- logs/                        
    |  HEAD                        
   |  HEAD                         
   |  commondir                    
   |  gitdir                       
   |  gitfile                      
   |  index                        
 |  COMMIT_EDITMSG                 
 |  FETCH_HEAD                     
 |  HEAD                           
 |  ORIG_HEAD                      
 |  config                         
 |  description                    
 |  index                          
 |  packed-refs                    

So try to read files from worktrees/worktree-test first and then a directory written in commondir.

Give me time to implement this.