Git: How can I automatically create a version number - it would be nice if a script could be executed automatically before git commit
Hi,
maybe I just have a knot in my head - but I don't find a solution.
I have a file with the "buildNumber" or/and with the branch-name (this ist like 1.2.3_release).
Alway before I commit to the git repository, this should be updated.
I also have a few changes to do in other files before I commit.
Now it would be very nice, if php-storm will run a script that would do that (like filewatcher) - but only if I start a commit.
I know there are git hooks - there is one git hook "pre-commit" - I use this to run a php-script.
The script runs - but the problem is, that changes from this script are made AFTER the commit.
How do you solve this problems?
I don't want to run the script by hand - is there a way to tell php-storm to do that for me (before commit run script)?
Or do I do something wrong with the git-hook?
Here is my example file console.php
<?php
$filePath = './version.txt';
if (file_exists($filePath) === false) {
touch($filePath);
}
$contentOldRaw = file_get_contents($filePath);
$contentOld = $contentOldRaw === '' ? 0 : (int)$contentOldRaw;
$contentNew = $contentOld + 1;
$contentNewString = (string)$contentNew;
file_put_contents($filePath, $contentNew);
$exitCode = 0;
exit($exitCode);
And thats my hook:
#!/bin/sh
php "./bin/console.php"
cu
Please sign in to leave a comment.
Hello,
Please vote for https://youtrack.jetbrains.com/issue/IDEA-111943 with thumb up button and leave a comment to let the developers know that this feature is needed.