3 # info.rb : output some info about a subversion url
5 # Example based on a blogpost by Mark Deepwell
6 # http://www.markdeepwell.com/2010/06/ruby-subversion-bindings/
8 ######################################################################
9 # Licensed to the Apache Software Foundation (ASF) under one
10 # or more contributor license agreements. See the NOTICE file
11 # distributed with this work for additional information
12 # regarding copyright ownership. The ASF licenses this file
13 # to you under the Apache License, Version 2.0 (the
14 # "License"); you may not use this file except in compliance
15 # with the License. You may obtain a copy of the License at
17 # http://www.apache.org/licenses/LICENSE-2.0
19 # Unless required by applicable law or agreed to in writing,
20 # software distributed under the License is distributed on an
21 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22 # KIND, either express or implied. See the License for the
23 # specific language governing permissions and limitations
25 ######################################################################
29 require "svn/ext/core"
34 # Prompt function mimicking svn's own prompt
35 simple_prompt = Proc.new do
36 |result, realm, username, default, may_save, pool|
38 puts "Authentication realm: #{realm}"
40 result.username = username
43 result.username = STDIN.gets.strip
45 print "Password for '#{result.username}': "
46 result.password = STDIN.gets.strip
49 gnome_keyring_prompt = Proc.new do
52 print "Password for '#{keyring_name}' GNOME keyring: "
57 puts "Usage: info.rb URL[@REV]"
59 ctx = Svn::Client::Context.new()
60 ctx.add_platform_specific_client_providers
61 ctx.add_simple_provider
62 ctx.add_simple_prompt_provider(2, simple_prompt)
63 ctx.add_username_provider
64 ctx.add_ssl_server_trust_file_provider
65 ctx.add_ssl_client_cert_file_provider
66 ctx.add_ssl_client_cert_pw_file_provider
68 # Allow asking for the gnome keyring password, in case the keyring is
70 if Svn::Ext::Core.respond_to?(:svn_auth_set_gnome_keyring_unlock_prompt_func)
71 Svn::Ext::Core::svn_auth_set_gnome_keyring_unlock_prompt_func(ctx.auth_baton, gnome_keyring_prompt)
74 repos_uri, revision = ARGV[0].split("@", 2)
76 revision = Integer(revision)
80 ctx.info(repos_uri, revision) do |path, info|
81 puts("Url: #{info.url}")
82 puts("Last changed rev: #{info.last_changed_rev}")
83 puts("Last changed author: #{info.last_changed_author}")
84 puts("Last changed date: #{info.last_changed_date}")
85 puts("Kind: #{info.kind}")
87 rescue Svn::Error => e
88 # catch a generic svn error
89 raise "Failed to retrieve SVN info at revision " + revision.to_s