I have a set of git hooks that constantly have their executable flag removed. I'm utterly at a loss for what might be doing it, but so far the only thing I've found that can even mitigate the problem somewhat is to have chmod +x ~/.git_template/hooks/* in my .bashrc file (it's almost always gone when I've rebooted the computer). Barring putting that in my PS1 function I'm running out of ideas and I'm wondering if there's anything to do with my particular set up that might be causing this or whether there's any way I can find out what process is causing this.

All my git repositories are created based on the template ~/.git_template which just holds a symbolic link to the hooks directory I use (so they're all using up to date versions). While it might not be completely straight-forward, I don't see anything in this that should cause this kind of (frankly) baffling behaviour.

Edit: In fact, I've noticed since adding a new hook (post-checkout) that all hooks have their executable permission removed every time this hook is executed (at least so far). Just in case this might be relevant, I'll paste the full git hook here:

#!/usr/bin/env node

var spawn = require('child_process').spawn;

var providedArguments = process.argv.slice(2)
var previousHead = providedArguments[0];
var newHead = providedArguments[1];

var changed = false;
var git = spawn('git', ['diff', previousHead, newHead, '--stat', '--', 'package.json']);
git.stdout.on('data', function(data) {
    changed = true;
git.on('exit', function() {
    if (changed) {
        console.log('package.json changed. Running npm install');
        spawn('npm', ['install'], { stdio: 'inherit' });
  • 1
    I would recommend trying inotifywait -m ~/.git_template and trying to see when something changes the mode of one of the files (an ATTRIB event). Unfortunately, it looks like there's no way to get the PID of the process that caused the event. – Dylan Frese Jul 28 '16 at 20:23

I would run strace -fo strace.log or the equivalent on your system if not Linux (like truss on Solaris, tusc on HP/UX, dtruss on OS/X...) on the command that (eventually) calls that hook.

Then, in strace.log, you would be able to see what does the chmod() (or fchmod() or fchmodat()...), and follow the thread of execve()s to see what caused the files permissions to be modified.

  • For Mac OSX users, the equivalent is dtruss – Charles Addis Jul 28 '16 at 20:17
  • @CharlesAddis, yes (added in), though in my little experience, dtruss on OS/X doesn't work properly if you're not superuser so can be cumbersome to use if you want to trace a command running as a normal user. – Stéphane Chazelas Jul 28 '16 at 20:54
  • I'm using Ubuntu 16.04. I'll give that a go when I get to the machine in question. Thanks! – Thor84no Jul 28 '16 at 22:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.