[darcs-users] Return value of hooks

Ben Franksen ben.franksen at online.de
Thu May 29 21:47:41 UTC 2014


Dmitry Bogatov wrote:
> It seems, that I can set {pre,post} -hooks for record command, but
> I cannot find a way to use their exit status.

Well, darcs commands fail immediately if the pre-hook failed. They also 
"fail" (that is, return the same exit code) if the post-hook failed.

However, this is of no use to you, since the pre-hook is run before the 
command even starts asking you which changes you want to record. And the 
post-hook may fail, and darcs may return the same exit code, but now it is 
too late: the changes to the repository are already made, and darcs does not 
roll back these changes.

> What I want, is get `darcs record` to ask me to choose chunks, apply
> them, run test and refuse to record, if it fails. Is it possible?

That is, you want a post-hook that, if it fails, causes darcs to roll back 
any changes it might have made.

> PS. Sorry for possible duplicate

I don't think this came up before. It would be a nice feature, but it would 
also need some serious re-factoring to implement it.

As for work-arounds:

There is darcs unrecord. You can wrap your post-hook into a script that 
checks for the failure, then unrecords the patch that just got recorded. If 
you want to make this more fail-safe, add a pre-hook that creates a tag with 
some unique name, then in case of a post-hook failure, unrecord everything 
up to and including this tag.

Cheers
Ben
-- 
"Make it so they have to reboot after every typo." -- Scott Adams




More information about the darcs-users mailing list