Cosium / git-code-format-maven-plugin

A maven plugin that automatically deploys code formatters as pre-commit git hook

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using git submodules

tdjonge opened this issue · comments

Hi,

I wish to use this plugin for one of my projects (called app-back), but have encountered an issue. The project I wish to use this plugin for is used as a submodule in another repository (called app-root) with the following structure.

app-root
- app-front (this is a git submodule)
- app-back (this is a git submodule) --> I want to use the plugin here
- docker-compose-file

The root project its sole purpose is to start app-front and app-back using Docker (irrelevant for the issue). The root project contains no other files, it is no Maven project and contains no pom.xml file. Furthermore, I do not wish to run the plugin on the app-front project.

The FAQ section states

If I have a multi-module project, do I need to install anything in the sub-projects?
You only need to put the plugin in your root project pom.xml. By default all submodules will be handled.

However, this is impossible as

  1. I cannot make changes to the root project
  2. Even if I could, it has no pom.xml file and is no Maven project
  3. I still want to be able to clone only the app-back project and work in there, without cloning the entire app-root project

Steps

I run mvn initialize on the app-back and notice two files being created. (I'm on Ubuntu btw)

  1. .../app-root/.git/modules/app-back/hooks/pre-commit
#!/bin/bash
"./app-back/hooks/app-back.git-code-format.pre-commit.sh"
  1. .../app-root/.git/modules/app-back/hooks/app-back.git-code-format.pre-commit.sh
#!/bin/bash
set -e
"/usr/share/maven/bin/mvn" -f "/<my-file-path>/app-root/app-back/pom.xml" com.cosium.code:git-code-format-maven-plugin:on-pre-commit 

On commit, the following error occurs

<my-file-path>/app-root/.git/modules/app-back/hooks/pre-commit: line 2: 
./app-back/hooks/app-back.git-code-format.pre-commit.sh: No such file or directory

Problem

As you can see, the content in file .../app-root/.git/modules/app-back/hooks/pre-commit points at the wrong location. It should be

#!/bin/bash
"../.git/modules/app-back/hooks/app-back.git-code-format.pre-commit.sh"

This path is obviously dependent on how the git repository is build (submodules or not?).

Possible solution

I've found a solution to the problem that works for both my cases

  1. If the project is a submodule, like I'm trying here
  2. If the project is a lone git repository

The solution is to change the content of the pre-commit file to

#!/bin/bash
"$(git rev-parse --git-dir)/hooks/app-back.git-code-format.pre-commit.sh"

Please note that I am using Linux and this is just a quick fix, I by no means have tested this thoroughly.

Question

Is it possible to achieve what I want using this plugin?

  • If yes, how?
  • If no, can/will you add this functionality to the plugin?

Thanks in advance.