Git Product home page Git Product logo

submodule_checker's Introduction

Git Submodule Check

Introduction

When working with git submodules the worst part is dealing with missed commits. That usually happens when you make changes to the submodule, but forget to push it to its remote repository before merging/pushing the parent repository.

There are many posts regarding this

pre-commit hook

The goal of this script is to help avoid this issue by comparing the local commits for each submodule against their corresponding commits on the remotes. If there's a mismatch, then the commit is aborted.

Installation

Copy this pre-commit script to .git/hooks folder on the repository you want to monitor. Now, everytime you try to commit the parent repository, the script will run and check the commit SHAs for each submodule to make sure you have the latest copy and you did not miss any push.

Sample Outputs

If all goes well, this is what you should see and commit will succeed:

user@mac ~/Work/MyClonedRepo (master)$ git commit -am "pushing parent and submodule is good" 
Checking submodules...
  Submodule [Vendor/lib_1] ... OK
  Submodule [Vendor/lib_2] ... OK
  Submodule [Vendor/lib_3] ... OK
returning state 0
[master 73ba08d] pushing parent and submodule is good
 1 file changed, 1 insertion(+)
user@mac ~/Work/MyClonedRepo (master)$ 

Otherwise, an error message is displayed and it lists the SHAs to help you resolve the issues:

user@mac ~/Work/MyClonedRepo (master)$ git commit -am "pushing parent and submodule is wrong"
Checking submodules...
  Submodule [Library/SampleLib] ... FAILED
 
Stop! Pre-commit condition failed.
Did you forget to push submodule [Library/SampleLib] to remote?
Cannot proceed until you do so.
Remote HASH: 12f8c095710278aadf18f04e3ca026ac7cdd7e72
Local HASH.: 3281d051f138bcd8c48d431ecdbdc54c2c6987db

user@mac ~/Work/MyClonedRepo (master)$ 

Notes

  • Script was tested with Mavericks 10.9.2
  • submodules of submodules are not checked

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.