-2

When I switch the branches using

git checkout <branchname>

can I fire a hook action to do some housekeeping stuff?

I added new Java sources to a branch and then switched to other branch, compiled classes from previous branch were left in the directory. These classes started interacting as classes are in the classpath and spring noticed the annotation on the classes.

I would like to fire mvn clean command to ensure these kinds of problems don't appear when I switch the branches.

Is there a way to do this?

user871199
  • 1,420
  • 19
  • 28

1 Answers1

1

From the docs

After you run a successful git checkout, the post-checkout hook runs;

you can use it to set up your working directory properly for your project environment.

This may mean moving in large binary files that you don’t want source controlled, auto-generating documentation, or something along those lines.


post-checkout

#!/bin/sh

# Output colors
red='\033[0;31m';
green='\033[0;32m';
yellow='\033[0;33m';
default='\033[0;m';

# personal touch :-)
echo "${red}"
echo "                                         "
echo "                   |ZZzzz                "
echo "                   |                     "
echo "                   |                     "
echo "      |ZZzzz      /^\            |ZZzzz  "
echo "      |          |~~~|           |       "
echo "      |        |-     -|        / \      "
echo "     /^\       |[]+    |       |^^^|     "
echo "  |^^^^^^^|    |    +[]|       |   |     "
echo "  |    +[]|/\/\/\/\^/\/\/\/\/|^^^^^^^|   "
echo "  |+[]+   |~~~~~~~~~~~~~~~~~~|    +[]|   "
echo "  |       |  []   /^\   []   |+[]+   |   "
echo "  |   +[]+|  []  || ||  []   |   +[]+|   "
echo "  |[]+    |      || ||       |[]+    |   "
echo "  |_______|------------------|_______|   "
echo "                                         "
echo "                                         "
echo "${default}"
echo "You have just checked out branch :-)"
exit 0;

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167