1

Here’s a common scenario:

You’re working on a project (such as, but not necessarily, a web app) with other developers.

  1. I decide we should use a certain open-sourced tool and add it to the project dependencies. Of course, I add it to our package manager, which is in source control. or

  2. Tom realizes we can speed up our database queries by adding an index and denormalizing a bit of data. He adds a migration and checks it in.

In either scenario, when other developers git pull or otherwise update their development environment, things are likely to break unless they run npm install / bundle / cocoapods chocolateygoodness / bower feathernest or python manage.py migrate / bundle exec rake migrate or whatever, and it’s not always obvious that this is the case. In fact, the other developer might not really be a developer at all, but perhaps a designer who is beautifying the cheezus out of our UI.

What I would really like is for every other developer, upon pulling the commit in question, to see something like this:

Updated! 

Please note you MUST RUN this command before continuing. 
(Stop your server first, if applicable)

$ ./magical_command_here --with-args

Alternatively, it would be amazing if running git status could output something like:

On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
Migrations need to be run. Please execute `database_migration_command`

Who has solutions for this problem?

Alan H.
  • 16,219
  • 17
  • 80
  • 113

2 Answers2

4

This is really not VCS's concern. This should be managed at build. The solutions is to include, as part of the source, a build script which takes care of this. If you add a dependency that is not already being taken care of by the build script, then update the build script and include it in the commit. Collaborators should know to run the build script as part of the development cycle.

Tonio
  • 1,516
  • 1
  • 15
  • 25
1

This is straightforward to solve with the use of Git hooks. I’m not sure about other VCS software but here is the documentation for the post-merge hook found it Git.

A simple example of how to use this check for things is to leverage the following Bash commands inside of that script to compare the current state of HEAD with the previous state of HEAD in your Git repository after the pull occurs.

You can use git and grep to achieve this within the post-merge hook script.

git diff --name-only 'HEAD@{1}' HEAD | grep "^$1" > /dev/null 2>&1
}

Here’s a link to a working script with comments that you can copy into your project to use with the Git post-merge hook.

rogeruiz
  • 106
  • 3