Discussion:
Post-commit hook
(too old to reply)
Pasha
2011-01-03 11:43:11 UTC
Permalink
I mange my web site using Fossil. I have a repository on the server as well as a
working copy there.

Any time I make changes and commit I'd like to notify the remote working
directory (which is also set as Apache's DocumentRoot) to update to
the latest version.

Thus the question: is it possible to have some kind of post-commit
hook on the repository
to automate the process?

This has probably been asked already, but I failed to find the answer.

Thanks.
--
Good luck,

Pasha Bastov
Richard Hipp
2011-01-03 11:58:59 UTC
Permalink
Post by Pasha
I mange my web site using Fossil. I have a repository on the server as well as a
working copy there.
Any time I make changes and commit I'd like to notify the remote working
directory (which is also set as Apache's DocumentRoot) to update to
the latest version.
Thus the question: is it possible to have some kind of post-commit
hook on the repository
to automate the process?
This has probably been asked already, but I failed to find the answer.
There is a branch in the Fossil source tree to do this, but I did not accept
that branch into the trunk.

I've got a plan for a better way to do various "hooks", but in order for it
to work cross-platform, I need code that will start a background process on
windows. By "background" process, I mean a process that will continue
running even after its parent process exits or is killed. If any windows
experts out there can explain to me how to do that, or provide sample code,
that will expedite getting the "hook" logic into the Fossil trunk.
Post by Pasha
Thanks.
--
Good luck,
Pasha Bastov
_______________________________________________
fossil-users mailing list
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users
--
D. Richard Hipp
***@sqlite.org
Pasha Bastov
2011-01-03 12:18:09 UTC
Permalink
Thanks Richard,

the only kind of background processes I'm familiar with on Windows is
windows services.
But I'm not sure it's what you need.
Post by Richard Hipp
Post by Pasha
I mange my web site using Fossil. I have a repository on the server as well as a
working copy there.
Any time I make changes and commit I'd like to notify the remote working
directory (which is also set as Apache's DocumentRoot) to update to
the latest version.
Thus the question: is it possible to have some kind of post-commit
hook on the repository
to automate the process?
This has probably been asked already, but I failed to find the answer.
There is a branch in the Fossil source tree to do this, but I did not accept
that branch into the trunk.
I've got a  plan for a better way to do various "hooks", but in order for it
to work cross-platform, I need code that will start a background process on
windows.  By "background" process, I mean a process that will continue
running even after its parent process exits or is killed.  If any windows
experts out there can explain to me how to do that, or provide sample code,
that will expedite getting the "hook" logic into the Fossil trunk.
Post by Pasha
Thanks.
--
Good luck,
Pasha Bastov
_______________________________________________
fossil-users mailing list
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users
--
D. Richard Hipp
_______________________________________________
fossil-users mailing list
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users
--
Why not? © Pasha Bastov
Nathaniel R. Reindl
2011-01-03 12:54:23 UTC
Permalink
Post by Richard Hipp
I've got a  plan for a better way to do various "hooks", but in order for it
to work cross-platform, I need code that will start a background process on
windows.  By "background" process, I mean a process that will continue
running even after its parent process exits or is killed.  If any windows
If memory serves, you can abuse CreateProcess() in Win32 land to this
end by setting the CREATE_BREAKAWAY_FROM_JOB and NO_WINDOW bits in
dwCreationFlags.

http://msdn.microsoft.com/en-us/library/ms682425%28v=vs.85%29.aspx

Unfortunately, my Win32 experience is somewhat limited (I've mostly
banged against what's called the Native API), and I currently don't
have access to a Win32 box with a development environment to test
this, so don't quote me on any of it. :)

/nrr
Antoine Chavasse
2011-03-29 10:42:21 UTC
Permalink
Sorry for the email necromancy, but since there are talks about post
commit hooks again and as it seems it would generally be a useful
feature, I remembered about the roadblock that Richard encountered
Post by Richard Hipp
I've got a  plan for a better way to do various "hooks", but in order for it
to work cross-platform, I need code that will start a background process on
windows.  By "background" process, I mean a process that will continue
running even after its parent process exits or is killed.  If any windows
experts out there can explain to me how to do that, or provide sample code,
that will expedite getting the "hook" logic into the Fossil trunk.
So I looked into the win32 process creation APIs and played with them
on a windows box. It turns out that CreateProcess
(http://msdn.microsoft.com/en-us/library/ms682425%28v=vs.85%29.aspx)
offers a range of options to run a process in a different console
window, without a console, or with its stdin / stdout bound to
arbitrary handles.

If you look in the creation flags you can pass to CreateProcess
(http://msdn.microsoft.com/en-us/library/ms684863(v=vs.85).aspx ), you
can give CREATE_NEW_CONSOLE to create a new console window for the new
process, CREATE_NO_WINDOW to have no window created for it, or
DETACH_PROCESS to just detach the process (which seems different than
CREATE_NO_WINDOW, I think it's for the case where you want to provide
your own file handle for stdin and stdout, which I didn't try).

Those three flags are mutually exclusive.

Below is a quick test program I made that launch the file you give it
on the command line. I used a small .bat file echoing things in a loop
in both the console and a file for testing that I launched with it.

With flags set at zero, predictably the script stopped running when I
closed the console (but kept running after the program ended).

With "CREATE_NEW_CONSOLE", it ran in a new, separate console window
that kept running even when the original console was closed.

With "CREATE_NO_WINDOW", it ran silently (the file kept growing) and
kept running after closing the console (I had to kill it through the
task manager).

With "DETACHED_PROCESS", nothing happened. Obviously the script simply
couldn't run without any form of input/output, but I suspect this is
the option to use when you want to provide your own file handles to
redirect stdin and stdout for the new process (in the STARTUPINFO
structure).


#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
//ShellExecute( NULL, "open", argv[1], NULL, NULL, 0 );
STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );

CreateProcess( NULL, // No module name (use command line)
argv[1], // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
CREATE_NO_WINDOW, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ); // Pointer to PROCESS_INFORMATION structure

return 0;
}

Ron Aaron
2011-01-03 12:00:37 UTC
Permalink
Post by Pasha
I mange my web site using Fossil. I have a repository on the server as well
as a working copy there.
I do the same.

But rather than rely on a post-commit hook, I rely on a bash script which:
pushes my changes to the server
logs in to the server and 'updates' the site (the DocumentRoot)
runs any other fix up stuff necessary

Best regards,
Ron
--
For privacy, my GPG key signature is: AD29415D
Continue reading on narkive:
Loading...