From: Joey Hess Date: Sun, 29 Aug 2010 18:53:57 +0000 (-0400) Subject: Added support for arbitrary pre and post hooks for all defined mr commands. For examp... X-Git-Url: https://git.madduck.net/code/myrepos.git/commitdiff_plain/4f4322be5574dcbb4f9e975b35300b34dd232368?ds=inline Added support for arbitrary pre and post hooks for all defined mr commands. For example, pre_commit is run before all commits; post_update is run after all updates. Closes: #481341 --- diff --git a/debian/changelog b/debian/changelog index 52249ed..d6dffc7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,9 @@ mr (0.50) UNRELEASED; urgency=low * Now supports the Fossil VCS. (Thanks, Jimmy Tang) * Added fixups hook, which can be used to run a command after a repository is checked out or updated. Closes: #590868 + * Added support for arbitrary pre and post hooks for all defined mr + commands. For example, pre_commit is run before all commits; post_update + is run after all updates. Closes: #481341 -- Joey Hess Sun, 15 Aug 2010 12:36:34 -0400 diff --git a/mr b/mr index 03cfdf3..e73f3c8 100755 --- a/mr +++ b/mr @@ -377,6 +377,13 @@ is checked out, or updated. This provides an easy way to do things like permissions fixups, or other tweaks to the repository content, whenever the repository is changed. +=item pre_ and post_ + +If a "pre_action" parameter is set, its command is run before mr performs the +specified action. Similarly, "post_action" parameters are run after mr +successfully performs the specified action. For example, "pre_commit" is +run before committing; "post_update" is run after updating. + =back When looking for a command to run for a given action, mr first looks for @@ -604,6 +611,10 @@ sub action { $s=~s/^\Q$topdir$subdir\E\/?//; print "mr $action: $topdir$subdir (in subdir $s)\n" unless $quiet; } + + my $hookret=hook("pre_$action", $topdir, $subdir); + return $hookret if $hookret != OK; + $command="set -e; ".$lib. "my_action(){ $command\n }; my_action ". join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV); @@ -641,11 +652,14 @@ sub action { return FAILED; } + my $ret=hook("post_$action", $topdir, $subdir); + return $ret if $ret != OK; + if (($is_checkout || $is_update)) { my $ret=hook("fixups", $topdir, $subdir); return $ret if $ret != OK; } - + return OK; } }