You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by se...@apache.org on 2020/06/07 15:18:41 UTC
[whimsy] branch master updated: Add svn_ method to abstract
_.system('svn' code
This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push:
new f4378cb Add svn_ method to abstract _.system('svn' code
f4378cb is described below
commit f4378cbe276457b5c3df4c54ef80a38fe7f3edb8
Author: Sebb <se...@apache.org>
AuthorDate: Sun Jun 7 16:18:33 2020 +0100
Add svn_ method to abstract _.system('svn' code
---
lib/spec/lib/svn_spec.rb | 16 +++++++++++
lib/whimsy/asf/svn.rb | 73 +++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 88 insertions(+), 1 deletion(-)
diff --git a/lib/spec/lib/svn_spec.rb b/lib/spec/lib/svn_spec.rb
index cb09aa3..95935c3 100644
--- a/lib/spec/lib/svn_spec.rb
+++ b/lib/spec/lib/svn_spec.rb
@@ -3,6 +3,7 @@
require 'spec_helper'
require 'whimsy/asf'
+require 'wunderbar'
describe ASF::SVN do
@@ -231,4 +232,19 @@ describe ASF::SVN do
end
end
+ describe "ASF::SVN.svn_" do
+ it "svn_('info') should return array" do
+ # TODO: this is a bit of a hack
+ _ = Wunderbar::JsonBuilder.new(Struct.new(:params).new({}))
+ repo = File.join(ASF::SVN.svnurl('attic-xdocs'),'_template.xml')
+ rc = ASF::SVN.svn_('info', repo, _)
+ expect(rc).to be(0)
+ # expect(res).to be(true).or be(false)
+ expect(_.target?(Hash)).to be(true)
+ hash = _.target? # TODO: another hack
+ expect(hash['transcript'].class).to equal(Array)
+ expect(hash['transcript'].include?('Name: _template.xml')).to be(true)
+ end
+ end
+
end
\ No newline at end of file
diff --git a/lib/whimsy/asf/svn.rb b/lib/whimsy/asf/svn.rb
index c9a73e1..81e6299 100644
--- a/lib/whimsy/asf/svn.rb
+++ b/lib/whimsy/asf/svn.rb
@@ -262,7 +262,7 @@ module ASF
return self.svn('list', path, {user: user, password: password})
end
- VALID_KEYS=[:args, :user, :password, :verbose, :env]
+ VALID_KEYS=[:args, :user, :password, :verbose, :env, :dryrun]
# low level SVN command
# params:
# command - info, list etc
@@ -329,6 +329,77 @@ module ASF
end
end
+ # low level SVN command for use in Wunderbar context (_json, _text etc)
+ # params:
+ # command - info, list etc
+ # path - the path to be used
+ # _ - wunderbar context
+ # options - hash of:
+ # :args - string or array of strings, e.g. '-v', ['--depth','empty']
+ # :env - environment: source for user and password
+ # :user, :password - used if env is not present
+ # :verbose - show command (including credentials) before executing it
+ # :dryrun - show command (excluding credentials), without executing it
+ #
+ # Returns:
+ # - status code
+ def self.svn_(command, path, _, options = {})
+ return nil, 'command must not be nil' unless command
+ return nil, 'path must not be nil' unless path
+
+ bad_keys = options.keys - VALID_KEYS
+ if bad_keys.size > 0
+ return nil, "Following options not recognised: #{bad_keys.inspect}"
+ end
+
+ # build svn command
+ cmd = ['svn', command, path, '--non-interactive']
+
+ args = options[:args]
+ if args
+ if args.is_a? String
+ cmd << args
+ elsif args.is_a? Array
+ cmd += args
+ else
+ return nil, "args '#{args.inspect}' must be string or array"
+ end
+ end
+
+ p cmd if options[:dryrun] # before creds added
+
+ # add credentials if required
+ open_opts = {}
+ env = options[:env]
+ if env
+ password = env.password
+ user = env.user
+ else
+ password = options[:password]
+ user = options[:user] if password
+ end
+ # password was supplied, add credentials
+ if password
+ creds = ['--no-auth-cache', '--username', user]
+ if self.passwordStdinOK?() && false # not sure how to support this
+ open_opts[:stdin_data] = password
+ creds << '--password-from-stdin'
+ else
+ creds += ['--password', password]
+ end
+ cmd << creds
+ end
+
+ p cmd if options[:verbose] # includes auth
+
+ # issue svn command
+ if options[:dryrun]
+ 0 # TODO is this the correct return value?
+ else
+ _.system cmd
+ end
+ end
+
# retrieve revision, [err] for a path in svn
def self.getRevision(path, user=nil, password=nil)
out, err = getInfo(path, user, password)