rhysd / committia.vim

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

Does not work for vcsh or fake bare git technique #37

Open DancingQuanta opened 7 years ago

DancingQuanta commented 7 years ago

I am using vcsh which allows me to version control my dotfiles with git. vcsh works by (taking a line from its manpage)

vcsh is using a technique called fake bare Git repositories, keeping $GIT_DIR in a different directory from $GIT_WORK_TREE which is pointed to $HOME.

So if I want to commit a change for a vcsh repo, I enter a vcsh environment then which have a different $GIT_DIR compared to $GIT_WORK_TREE for that repo.

committia chokes on this $GIT_DIR as shown in the following error upon committing.

Error detected while processing function committia#open[14]..<SNR>65_open_multicolumn[3]..<SNR>65_open_diff_window[1]..<SN
R>65_open_window[1]..committia#git#diff[1]..<SNR>66_search_git_dir_and_work_tree:
line   24:
E605: Exception not caught: committia: git: Failed to get git-dir from $GIT_DIR
Error detected while processing function committia#open:
line   14:
E171: Missing :endif
Error detected while processing function dein#autoload#_on_default_event[23]..<SNR>47_source_events:
line   12:
E171: Missing :endif

Can committia be adapted to support fake git repo technique please?

rhysd commented 7 years ago

Thank you for your report. Yeah, committia.vim does not surrpot bare repository for now. But I can investigate how to support and if it's reasonable, I'll add the support. Anyway, investigation is needed.

DancingQuanta commented 7 years ago

Yes, this is more complex use of bare repos. Actually it is called fake bare repos and so I have no idea if a bare repo is actually involved. You may need to look at how vcsh works to understand the fake bare thing. There are other tools that understand this for example liquidprompt for bash can sense it is in a git repo which I assume is due to executing a git command. I don't know if you wanted committia to launch calls to git to check whether it is in a git repo or not.

rbialon commented 6 years ago

vcsh should set the GIT_DIR and GIT_WORK_TREE environment variables. I use an alias for managing my home files, similar to vcsh but simpler:

alias homegit='GIT_DIR=$HOME/.dotfiles/ GIT_WORK_TREE=$HOME/ git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'

I was able to fix this issue by including

    if !empty($GIT_DIR) && !empty($GIT_WORK_TREE)
        return [$GIT_DIR, $GIT_WORK_TREE]
    endif

right after function! s:search_git_dir_and_work_tree() abort in autoload/committia/git.vim.

@DancingQuanta Can you check if this works with vcsh, too?

DancingQuanta commented 6 years ago

Oh it is embarrassing, vcsh does not set the GIT_WORK_TREE variable although it is normally VCSH_BASE=$HOME. I will have to contact the vcsh's author about this.

EDIT

Actually when a VCSH repo is created, core.worktree is set in the repo's config. So the work tree is always set to this value when activating the VCSH repo (through exporting GIT_DIR pointing at repo's location).

DancingQuanta commented 6 years ago

The description of #42 said that #42 does not fix #37 because vcsh did not touch GIT_WORK_TREE but it does set core.worktree attribute in the repo's config. I will do some investigating on solutions. A project, vim-fugitive/pull/575, have been working for vcsh.

rbialon commented 6 years ago

Yes, that's right. If GIT_DIR is set correctly, the following will retrieve the workdir from the repo's config:

git config --local --get core.worktree
rhysd commented 6 years ago

So, should we also check core.worktree config value here?

rbialon commented 6 years ago

This depends on the type of repo: In a bare repo,

    bare = true
    worktree = /path/to/worktree

results in fatal: core.bare and core.worktree do not make sense. (See https://github.com/git/git/commit/fada767463b599951b37bd544379a1d18dcf9370 ) So the value should only be honored if the repo isn't a bare repo.

DancingQuanta commented 6 years ago

I asked vcsh's author about exporting GIT_WORK_TREE RichiH/vcsh#248. I like to wait for his answer.

rhysd commented 6 years ago

Sure. I'll wait for response.