Skip to content

Commit 4082d26

Browse files
Check for provided commit message
In order to not overwrite the commit message with just the contents of the file we check for a given commit message. If a commit message is specified the file will be ignored.
1 parent 9dd1c57 commit 4082d26

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/Hook/Message/Action/PrepareFromFile.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
/**
2424
* Class PrepareFromFile
2525
*
26+
* Example configuration:
27+
* {
28+
* "action": "\\CaptainHook\\App\\Hook\\Message\\Action\\PrepareFromFile"
29+
* "options": {
30+
* "file": ".git/CH_MSG_CACHE"
31+
* }
32+
* }
33+
*
2634
* @package CaptainHook
2735
* @author Sebastian Feldmann <[email protected]>
2836
* @link https://github.com/captainhookphp/captainhook
@@ -47,13 +55,18 @@ public function execute(Config $config, IO $io, Repository $repository, Config\A
4755
if (empty($options->get('file', ''))) {
4856
throw new ActionFailed('PrepareFromFile requires \'file\' option');
4957
}
50-
if (!is_file($cacheFile)) {
51-
return;
58+
59+
// if there is a commit message don't do anything just delete the file
60+
if ($repository->getCommitMsg()->isEmpty()) {
61+
if (!is_file($cacheFile)) {
62+
return;
63+
}
64+
$msg = (string)file_get_contents($cacheFile);
65+
$repository->setCommitMsg(
66+
new CommitMessage($msg, $repository->getCommitMsg()->getCommentCharacter())
67+
);
5268
}
53-
$msg = (string) file_get_contents($cacheFile);
54-
$repository->setCommitMsg(
55-
new CommitMessage($msg, $repository->getCommitMsg()->getCommentCharacter())
56-
);
69+
5770
if (!$options->get('keep', false)) {
5871
unlink($cacheFile);
5972
}

0 commit comments

Comments
 (0)