Home > Blockchain >  git pre-commit hook doesn't work as expected (or it's me)
git pre-commit hook doesn't work as expected (or it's me)

Time:09-13

I have a pre-commit which is really simple :

[xavier@imladris python-requests]$ cat .git/hooks/pre-commit
rm -f BUILDLOCK

This does not work as the name suggests : the file is removed from local repository, but remains on distant, which makes my local repo marked as dirty after the commit.

Did I misunderstood the doc ? In this case, which is the proper hook to accomplish what I need, ie removing the Lock file, the commit the modifs, as well as the removal of the file

Thanks, regards,

Xavier

CodePudding user response:

From what I understand you want to not only remove the file, but also commit the removal?

Then don't use use rm, but git rm instead.

git rm -f BUILDLOCK

CodePudding user response:

After we run git commit and before it's done, pre-commit is invoked. The result of pre-commit determines if git commit is to be done or aborted.

In your question, you mention that removing BUILDLOCK results in a dirty repository. pre-commit works as expected. But it's not proper to commit BUILDLOCK in the first place. Instead, it's suggested to add it in .gitignore. It seems that it's used as a lock file indicating that the build process is running, right? If so, the build process is responsible to create and remove it.

CodePudding user response:

Thanks for the quick answers.

It works now with this content

#!/bin/bash
rm -f BUILDLOCK
git rm --ignore-unmatch -q BUILDLOCK

Cheers,

Xavier

  •  Tags:  
  • git
  • Related