jish/pre-commit

Workflow with submodules

Closed this issue · 4 comments

I have a workflow that involves making commits to a submodule (yet to google whether this is frowned upon, but have been using this setup for about 8 years without issue).

Because of this, .git is a pointer a dir in the parent repo rather than an actual dir:

submodule $ cat .git
gitdir: ../../../.git/modules/vendor/gems/submodule

As such pre-commit fails on the install:

zacharys-imac:pledge_core zach$ pre-commit install
/Users/zach/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/fileutils.rb:250:in `mkdir': File exists @ dir_s_mkdir - .git (Errno::EEXIST)

Is there any work around for this?

are you trying to install the hook in an actual submodule of git repository?
can you layout an minimal example so I can try reproduce it?

Yeah, for some reason submodule .git dir is stored inside the supermodule, and the .git is a reference file rather than a dir. Performing all the usual git commands works fine inside the submodule, so it works as an edit environment, but gems such as precommit that assume ".git" is a dir don't work.

Thanks for the quick response.

zacharys-imac:Sites zach$ git clone https://github.com/babelian/precommit_repo.git
Cloning into 'precommit_repo'...
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 3 (delta 0)
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.

zacharys-imac:Sites zach$ cd precommit_repo/

zacharys-imac:precommit_repo zach$ git submodule init
Submodule 'precommit_submodule' (https://github.com/babelian/precommit_submodule.git) registered for path 'precommit_submodule'

zacharys-imac:precommit_repo zach$ git submodule update
Cloning into 'precommit_submodule'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 3 (delta 0)
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.
Submodule path 'precommit_submodule': checked out '902234d49d82049acb138c4023e29d964816fb7f'

zacharys-imac:precommit_repo zach$ cd precommit_submodule/

zacharys-imac:precommit_submodule zach$ pre-commit install
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:245:in `mkdir': File exists - .git (Errno::EEXIST)
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:245:in `fu_mkdir'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:219:in `block (2 levels) in mkdir_p'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:217:in `reverse_each'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:217:in `block in mkdir_p'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:203:in `each'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:203:in `mkdir_p'
    from /Library/Ruby/Gems/2.0.0/gems/pre-commit-0.19.0/lib/pre-commit/installer.rb:29:in `install'
    from /Library/Ruby/Gems/2.0.0/gems/pre-commit-0.19.0/lib/pre-commit/cli.rb:40:in `execute_install'
    from /Library/Ruby/Gems/2.0.0/gems/pre-commit-0.19.0/lib/pre-commit/cli.rb:20:in `execute'
    from /Library/Ruby/Gems/2.0.0/gems/pre-commit-0.19.0/bin/pre-commit:9:in `<top (required)>'
    from /usr/bin/pre-commit:23:in `load'
    from /usr/bin/pre-commit:23:in `<main>'

zacharys-imac:precommit_submodule zach$ ls -a
.       ..      .git        submodule_file

zacharys-imac:precommit_submodule zach$ cat .git 
gitdir: ../.git/modules/precommit_submodule

zacharys-imac:precommit_submodule zach$ ls ../.git/modules/precommit_submodule
HEAD        branches    config      description hooks       index       info        logs        objects     packed-refs refs

zacharys-imac:precommit_submodule zach$ ls ../.git/modules/precommit_submodule/hooks
applypatch-msg.sample       post-update.sample      pre-commit.sample       pre-rebase.sample       update.sample
commit-msg.sample       pre-applypatch.sample       pre-push.sample         prepare-commit-msg.sample

@jish this should do it, there should be way to get the root from git - but I'm not sure it would be the best way to go (like using git-ui helper with no git in path)

@mpapis seems to work (install and manual checks ran), thanks for the quick fix.