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 0f0b9ff Add msg: and depth: shorthand options
0f0b9ff is described below
commit 0f0b9ff3be41bd0765567ab1d2d5364cf348c227
Author: Sebb <[email protected]>
AuthorDate: Fri Jun 12 13:45:35 2020 +0100
Add msg: and depth: shorthand options
---
lib/spec/lib/svn_spec.rb | 19 ++++++++++++++++++-
lib/spec/lib/svn_wunderbar_spec.rb | 27 +++++++++++++++++++++++++++
lib/whimsy/asf/svn.rb | 30 +++++++++++++++++++++++++-----
3 files changed, 70 insertions(+), 6 deletions(-)
diff --git a/lib/spec/lib/svn_spec.rb b/lib/spec/lib/svn_spec.rb
index d020851..7f80ead 100644
--- a/lib/spec/lib/svn_spec.rb
+++ b/lib/spec/lib/svn_spec.rb
@@ -249,5 +249,22 @@ describe ASF::SVN do
out, err = ASF::SVN.svn('info',[path1, path2], {args:
['--show-item','kind']})
expect(out).to match(/^file +https:/)
end
+
+ it "svn('help', 'help', {args: ['--depth','empty'], dryrun: true}) should
return the same as {depth: 'files'}" do
+ out1, err1 = ASF::SVN.svn('help', 'help', {args: ['--depth','empty'],
dryrun: true})
+ out2, err2 = ASF::SVN.svn('help', 'help', {depth: 'empty', dryrun: true})
+ expect(out1).to eq(out2)
+ expect(err1).to eq(nil)
+ expect(err2).to eq(nil)
+ end
+
+ it "svn('help', 'help', {args: ['--message','text'], dryrun: true}) should
return the same as {msg: 'text'}" do
+ out1, err1 = ASF::SVN.svn('help', 'help', {args: ['--message','text'],
dryrun: true})
+ out2, err2 = ASF::SVN.svn('help', 'help', {msg: 'text', dryrun: true})
+ expect(out1).to eq(out2)
+ expect(err1).to eq(nil)
+ expect(err2).to eq(nil)
+ end
+
end
-end
\ No newline at end of file
+end
diff --git a/lib/spec/lib/svn_wunderbar_spec.rb
b/lib/spec/lib/svn_wunderbar_spec.rb
index b3ceb7e..0334afe 100644
--- a/lib/spec/lib/svn_wunderbar_spec.rb
+++ b/lib/spec/lib/svn_wunderbar_spec.rb
@@ -65,6 +65,33 @@ describe "ASF::SVN.svn_" do
expect(out['transcript'].class).to equal(Array)
expect(out['transcript'].join("\n")).to match(/svn: E200009:/)
end
+
+ it "svn_('help', 'help', _, {args: ['--depth','empty'], dryrun: true})
should return the same as {depth: 'files'}" do
+ rc1, out1 = _json do |_|
+ ASF::SVN.svn_('help', 'help', _, {args: ['--depth','empty'], dryrun:
true})
+ end
+ rc2, out2 = _json do |_|
+ ASF::SVN.svn_('help', 'help', _, {depth: 'empty', dryrun: true})
+ end
+ expect(rc1).to eq(0)
+ expect(rc2).to eq(0)
+ expect(out1).to eq(out2)
+ end
+
+ it "svn_('help', 'help', _, {args: ['--message','text'], dryrun: true})
should return the same as {msg: 'text'}" do
+ rc1, out1 = _json do |_|
+ ASF::SVN.svn_('help', 'help', _, {args: ['--message','text'], dryrun:
true})
+ end
+ rc2, out2 = _json do |_|
+ ASF::SVN.svn_('help', 'help', _, {msg: 'text', dryrun: true})
+ end
+ expect(rc1).to eq(0)
+ expect(rc2).to eq(0)
+ expect(out1).to eq(out2)
+ end
+
+
+
end
describe "ASF::SVN.update" do
diff --git a/lib/whimsy/asf/svn.rb b/lib/whimsy/asf/svn.rb
index 3feaa2f..dec1a2d 100644
--- a/lib/whimsy/asf/svn.rb
+++ b/lib/whimsy/asf/svn.rb
@@ -262,19 +262,23 @@ module ASF
return self.svn('list', path, {user: user, password: password})
end
- VALID_KEYS=[:args, :user, :password, :verbose, :env, :dryrun]
+ VALID_KEYS=[:args, :user, :password, :verbose, :env, :dryrun, :msg, :depth]
# low level SVN command
# params:
# command - info, list etc
# path - the path(s) to be used - String or Array of Strings
# options - hash of:
# :args - string or array of strings, e.g. '-v', ['--depth','empty']
+ # :msg - shorthand for {args: ['--message', value]}
+ # :depth - shorthand for {args: ['--depth', value]}
# :env - environment: source for user and password
# :user, :password - used if env is not present
- # :verbose - show command
- # Returns either:
+ # :verbose - show command on stdout
+ # :dryrun - return command array as [cmd] without executing it (excludes
auth)
+ # Returns:
# - stdout
# - nil, err
+ # - [cmd] if :dryrun
def self.svn(command, path , options = {})
return nil, 'command must not be nil' unless command
return nil, 'path must not be nil' unless path
@@ -298,6 +302,12 @@ module ASF
end
end
+ msg = options[:msg]
+ cmd += ['--message', msg] if msg
+
+ depth = options[:depth]
+ cmd += ['--depth', depth] if depth
+
open_opts = {}
env = options[:env]
if env
@@ -307,8 +317,8 @@ module ASF
password = options[:password]
user = options[:user] if password
end
- # password was supplied, add credentials
- if password
+ # password was supplied, add credentials
+ if password and not options[:dryrun] # don't add auth for dryrun
cmd += ['--username', user, '--no-auth-cache']
if self.passwordStdinOK?()
open_opts[:stdin_data] = password
@@ -328,6 +338,8 @@ module ASF
p cmd if options[:verbose]
+ return [cmd] if options[:dryrun]
+
# issue svn command
out, err, status = Open3.capture3(*cmd, open_opts)
if status.success?
@@ -344,6 +356,8 @@ module ASF
# _ - wunderbar context
# options - hash of:
# :args - string or array of strings, e.g. '-v', ['--depth','empty']
+ # :msg - shorthand for {args: ['--message', value]}
+ # :depth - shorthand for {args: ['--depth', value]}
# :env - environment: source for user and password
# :user, :password - used if env is not present
# :verbose - show command (including credentials) before executing it
@@ -380,6 +394,12 @@ module ASF
end
end
+ msg = options[:msg]
+ cmd += ['--message', msg] if msg
+
+ depth = options[:depth]
+ cmd += ['--depth', depth] if depth
+
# add credentials if required
env = options[:env]
if env