Forum: Ruby svn pre-commit hook

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A87f7a014c624587fab0d3d78c5b9c18?d=identicon&s=25 Bil Kleb (Guest)
on 2006-03-10 22:29
(Received via mailing list)
OK, I give up.

Can someone (Kou?) please sketch out how to intercept
a Subversion transaction with a pre-commit hook and
throw each file matching, say, /\.rb$/ to some StyleChecker?

Based on Kou's svnlook,

  https://svn.collab.net/repos/svn/trunk/tools/examp...

and the bindings,

  http://svn.collab.net/repos/svn/trunk/subversion/b...

it seems that Svn:Fs might be the answer, but I'm having
trouble figuring out SVN transactions -- the manual says
very little about these creatures.

Thanks,
F3b7109c91841c7106784d229418f5dd?d=identicon&s=25 Justin Collins (Guest)
on 2006-03-10 22:44
(Received via mailing list)
Bil Kleb wrote:
> and the bindings,
> http://fun3d.larc.nasa.gov
>

I don't know about pre-commit hooks, but here's a post-commit hook I
wrote the other day. Not fancy or anything, but will maybe give you an
idea?
I just used the normal 'svnlook'.

> 	deleted = Array.new
> 			modified << changed[1..-1]
>
> 	end
> repository = ARGV[0]
> From: SVN <svn@host.net>
>
>
> 		smtp.send_message(message, 'fake@fake.net', recipients)
>
> }
>

-Justin
A87f7a014c624587fab0d3d78c5b9c18?d=identicon&s=25 Bil Kleb (Guest)
on 2006-03-10 23:06
(Received via mailing list)
Justin Collins wrote:
>
> I don't know about pre-commit hooks, but here's a post-commit hook I
> wrote the other day. Not fancy or anything, but will maybe give you an
> idea?

Thanks.

> I just used the normal 'svnlook'.

If you have the SVN Ruby bindings compiled, you could use Kouhei's
commit-email.rb for post-hook mailings (and RSS feed):

  https://svn.collab.net/repos/svn/trunk/tools/hook-...

If you want HTML output also, see

  https://svn.collab.net/repos/svn/trunk/tools/examp...

Regards,
Ee6ffca720cc428d70247dcd7377dd48?d=identicon&s=25 Kouhei Sutou (Guest)
on 2006-03-13 16:00
(Received via mailing list)
Hi,

In <dusqov$mbv$1@vilya.larc.nasa.gov>
  "svn pre-commit hook" on Sat, 11 Mar 2006 06:28:43 +0900,
  Bil Kleb <Bil.Kleb@NASA.gov> wrote:

> Can someone (Kou?) please sketch out how to intercept
> a Subversion transaction with a pre-commit hook and
> throw each file matching, say, /\.rb$/ to some StyleChecker?

What about attached script?

You can use the attached script with the following
pre-commit script:

  #!/bin/sh

  REPOS="$1"
  TXN="$2"

  /.../ruby \
    /.../pre-check-file.rb "$REPOS" "$TXN" \
    -p PATTERN1 -c CHECK_COMMAND1 \
    -p PATTERN2 -c CHECK_COMMAND2 \
    ... \
    || exit 1

  exit 0

For example (reject space indented Ruby scripts and C programs):

  #!/bin/sh

  REPOS="$1"
  TXN="$2"

  /usr/bin/ruby \
    ~/work/ruby/pre-check-file.rb "$REPOS" "$TXN" \
    -p \.rb$ -c 'grep -v ^ ' \
    -p \.c$ -c 'grep -v ^ ' \
    || exit 1

  exit 0


Thanks,
A87f7a014c624587fab0d3d78c5b9c18?d=identicon&s=25 Bil Kleb (Guest)
on 2006-03-13 16:16
(Received via mailing list)
Kouhei Sutou wrote:
> Hi,

Hello.

> What about attached script?

Excellent, Thanks!

This is the nugget I most craved:

>   def changed_paths(base_rev=nil)
>     base_rev ||= @txn.base_revision
>     base_root = @fs.root(base_rev)
>     editor = Svn::Delta::ChangedEditor.new(@root, base_root)
>     base_root.dir_delta('', '', @root, '', editor)
>     (editor.added_files + editor.updated_files).uniq.sort
>   end

Thanks again,
This topic is locked and can not be replied to.