Skip to content
Merged
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
24 changes: 20 additions & 4 deletions GVFS/GitHooksLoader/GitHooksLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,25 @@ int ExecuteHook(const std::wstring &applicationName, wchar_t *hookName, int argc
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
si.dwFlags = STARTF_USESTDHANDLES;
Comment on lines -115 to -117
Copy link
Member

Choose a reason for hiding this comment

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

So what you're saying is that this explicit redirection of stdout/stderr currently does not work? This is puzzling because the GitHooksLoader.exe process should have the correct handles, and this way of creating the child process should work...

Copy link
Contributor Author

@tyrielv tyrielv May 13, 2025

Choose a reason for hiding this comment

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

Yes, it does not work. For example running git status on an unmounted gvfs repo displays only the standard fatal: pre-command hook aborted command message, and not the specific message about needing to mount.

The documentation for CREATE_NO_WINDOW says The process is a console application that is being run without a console window. Therefore, the console handle for the application is not set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated this to more closely match how git-wrapper in microsoft/git works - checking explicitly for a console with CONOUT$, and if found then use default behavior (ie don't set CREATE_NO_WINDOW, don't explicitly forward handles as they are forwarded by default), falling back to the current behavior if CONOUT$ is not found (set CREATE_NO_WINDOW and explicitly forward handles)

Copy link
Member

Choose a reason for hiding this comment

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

Excellent, thank you! Did you test this a bit, including running git status on an unmounted GVFS repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it now displays The repo does not appear to be mounted. Use 'gvfs status' to check. fatal: pre-command hook aborted command
instead of just the fatal line.

DWORD creationFlags = 0;
HANDLE consoleHandle;

/* If we have a console, use it (ie allow default behavior)*/
if ((consoleHandle = CreateFile(L"CONOUT$", GENERIC_WRITE,
FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL)) !=
INVALID_HANDLE_VALUE)
CloseHandle(consoleHandle);
else {
/* Otherwise, forward stdout/err in case they were redirected,
* but do not allow creating a window.*/
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
/* Git disallows stdin from hooks */
si.dwFlags = STARTF_USESTDHANDLES;

creationFlags |= CREATE_NO_WINDOW;
}

ZeroMemory(&pi, sizeof(pi));

Expand All @@ -135,7 +151,7 @@ int ExecuteHook(const std::wstring &applicationName, wchar_t *hookName, int argc
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
TRUE, // Set handle inheritance to TRUE
CREATE_NO_WINDOW, // Process creation flags
creationFlags , // Process creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
Expand Down
Loading