Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3602202
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:43:00+00:00 2026-05-18T20:43:00+00:00

I would like to add an update hook to git that prevents people from

  • 0

I would like to add an update hook to git that prevents people from pushing java code that won’t compile. Ideally it would call javac, see the result, and either allow or reject the push.

The most common example of something I want to prevent is somebody not committing all their changes thus breaking the build. However, it is my understanding that git hooks run on the client (not the server) so if the above happens the hook will still allow the push.

What is the best way to prevent people breaking the build with incomplete commits?

UPDATE:

Got a primitive version of the hook working, thanks for all the help!

Excerpt from update hook:

### make sure code compiles
## currently does this by copying the state of the repository as of the pushed code and attempting to build it

# for now, hard coded as C:\Windows\Temp
copydir="/c/Windows/Temp/git_hook_compile_copy"

echo "making copy of $newrev to $copydir" >&2
rm -rf "$copydir"
mkdir "$copydir"
git archive $newrev | tar -x -C $copydir/
if [ "$?" != "0" ]; then
    echo "*** unable to make copy of code" >&2
    exit 1
fi
echo "attempting to build $newrev" >&2
"$ANT_HOME/bin/ant" -file "$copydir/appropriatePath/build.xml"
if [ "$?" != "0" ]; then
    echo "*** code does not compile" >&2
    exit 1
fi

(note this is for a windows environment and relies on ANT_HOME (and thus JAVA_HOME) environment variables being defined)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:43:00+00:00Added an answer on May 18, 2026 at 8:43 pm

    Git server and client do not differ that much ;-). So all hooks that run on “client” will run on “server” if same events occur on the server, of course.

    For example, update hook, totally falls into this category. It’s called after a branch was updated, and if this hook returns nonzero status, the update is canceled. So you might want to put compilation there, and return its result. All the messages you print from hook will be shown to the user who commits on his console. This is quite handy, since he can see error messages from your build script, and fix it.

    Even if you run two compilations concurrently, git repository won’t lose commits, due to use of “old refname” argument in its update hook. However, it might then happen that a committer waits for compilation, and his ref isn’t pushed because someone else got his one pushed instead.

    A default git repository contains a nice example of an update hook (named update.sample). Refer to it if you need a definitive example.

    However, if compilation is too long, and the rate of commits exceeds the frequency you can compile your code with, you might want to use more advanced solutions. Commenters suggest to look for “continuous integration” in google.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.