Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #592: Exotic structure with Composer and GrumPHP in subfolder compared to GIT #607

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/hooks/local/commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GIT_EMAIL=$(git config user.email)
COMMIT_MSG_FILE=$1

# Fetch the GIT diff and format it as command input:
DIFF=$(git -c diff.mnemonicprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged | cat)
DIFF=$(git -c diff.mnemonicprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged --src-prefix="a/${HOOK_PREFIX}" --dst-prefix="b/${HOOK_PREFIX}" | cat)

# Run GrumPHP
(cd "${HOOK_EXEC_PATH}" && printf "%s\n" "${DIFF}" | exec $(HOOK_COMMAND) "--git-user=$GIT_USER" "--git-email=$GIT_EMAIL" "$COMMIT_MSG_FILE")
2 changes: 1 addition & 1 deletion resources/hooks/local/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#

# Fetch the GIT diff and format it as command input:
DIFF=$(git -c diff.mnemonicprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged | cat)
DIFF=$(git -c diff.mnemonicprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged --src-prefix="a/${HOOK_PREFIX}" --dst-prefix="b/${HOOK_PREFIX}" | cat)

# Run GrumPHP
(cd "${HOOK_EXEC_PATH}" && printf "%s\n" "${DIFF}" | exec $(HOOK_COMMAND) '--skip-success-output')
2 changes: 1 addition & 1 deletion resources/hooks/vagrant/commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ COMMIT_MSG_FILE=$1
COMMIT_MSG=$(cat "${COMMIT_MSG_FILE}")

# Fetch the GIT diff and format it as command input:
DIFF=$(git -c diff.mnemonicprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged | cat)
DIFF=$(git -c diff.mnemonicprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged --src-prefix="a/${HOOK_PREFIX}" --dst-prefix="b/${HOOK_PREFIX}" | cat)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really not sure if this file needs to be updated as well. I did just to be sure, but have no way of testing it.


# Copy the commit message and run GrumPHP
vagrant ssh --command '$(which sh)' << COMMANDS
Expand Down
2 changes: 1 addition & 1 deletion resources/hooks/vagrant/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#

# Fetch the GIT diff and format it as command input:
DIFF=$(git -c diff.mnemonicprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged | cat)
DIFF=$(git -c diff.mnemonicprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged --src-prefix="a/${HOOK_PREFIX}" --dst-prefix="b/${HOOK_PREFIX}" | cat)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really not sure if this file needs to be updated as well. I did just to be sure, but have no way of testing it.


# Run GrumPHP
vagrant ssh --command '$(which sh)' << COMMANDS
Expand Down
1 change: 1 addition & 0 deletions src/Console/Command/Git/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ protected function parseHookBody(string $hook, SplFileInfo $templateFile): strin
{
$content = $this->filesystem->readFromFileInfo($templateFile);
$replacements = [
'${HOOK_PREFIX}' => $this->paths()->getGitPrefix(),
'${HOOK_EXEC_PATH}' => $this->paths()->getGitHookExecutionPath(),
'$(HOOK_COMMAND)' => $this->generateHookCommand('git:'.$hook),
];
Expand Down
8 changes: 8 additions & 0 deletions src/Console/Helper/PathsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ public function getGitHookExecutionPath(): string
return $this->fileSystem->makePathRelative($this->getWorkingDir(), $this->getAbsolutePath($gitPath));
}

/**
* Returns the git dir from the configfile with ONLY a trailing slash, no leading slash.
*/
public function getGitPrefix(): string
{
return trim($this->config->getGitDir(), '/') . '/';
}

/**
* Returns the directory where the git hooks are installed.
*/
Expand Down