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 fcee33f Replace svnmucc_ tmpdir param with options array fcee33f is described below commit fcee33f69d305e3267cbf3f9891a6251d221c307 Author: Sebb <s...@apache.org> AuthorDate: Tue Jun 30 22:44:10 2020 +0100 Replace svnmucc_ tmpdir param with options array --- lib/spec/lib/svn_wunderbar_spec.rb | 34 ++++++++++++++++++++++++++++++---- lib/whimsy/asf/svn.rb | 28 ++++++++++++++++++++++------ 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/lib/spec/lib/svn_wunderbar_spec.rb b/lib/spec/lib/svn_wunderbar_spec.rb index 4d89cf2..7186d2e 100644 --- a/lib/spec/lib/svn_wunderbar_spec.rb +++ b/lib/spec/lib/svn_wunderbar_spec.rb @@ -242,9 +242,9 @@ describe "ASF::SVN.svnmucc_" do expect(ts).to be_kind_of(Array) expect(ts[0]).to match(/--revision 123/) end - it "svnmucc_([['help']],'test',ENV_.new,_,nil,nil,nil) should not show revision in command" do + it "svnmucc_([['help']],'test',ENV_.new,_,nil) should not show revision in command" do rc, out = _json do |_| - ASF::SVN.svnmucc_([['help']],'test',ENV_.new,_,nil,nil) + ASF::SVN.svnmucc_([['help']],'test',ENV_.new,_,nil) end expect(rc).to eq(0) expect(out).to be_kind_of(Hash) @@ -252,12 +252,12 @@ describe "ASF::SVN.svnmucc_" do expect(ts).to be_kind_of(Array) expect(ts[0]).not_to match(/--revision/) end - it "svnmucc_([['help']],'test',ENV_.new,_,nil,tmpdir,nil) should have tmpdir in command" do + it "svnmucc_([['help']],'test',ENV_.new,_,nil,{tmpdir: tmpdir}) should have tmpdir in command" do tmpdir=Dir.mktmpdir path=File.join(tmpdir,'*') expect(Dir[path]).to eq([]) rc, out = _json do |_| - ASF::SVN.svnmucc_([['help']],'test',ENV_.new,_,nil,tmpdir) + ASF::SVN.svnmucc_([['help']],'test',ENV_.new,_,nil,{tmpdir: tmpdir}) end expect(rc).to eq(0) expect(out).to be_kind_of(Hash) @@ -266,4 +266,30 @@ describe "ASF::SVN.svnmucc_" do expect(ts[0]).to match(%r{--extra-args #{tmpdir}}) expect(Dir[path]).to eq([]) # no files remaining end + it "svnmucc_([['help']],'test',ENV_.new,_,nil,{dryrun: true}) should echo params" do + rc, out = _json do |_| + ASF::SVN.svnmucc_([['help']],'test',ENV_.new,_,nil,{dryrun: true}) + end + expect(rc).to eq(0) + expect(out).to be_kind_of(Hash) + ts = out['transcript'] + expect(ts).to be_kind_of(Array) + expect(ts.size).to eq(2) + expect(ts[0]).to match(%r{\$ echo svnmucc .*--message test}) + expect(ts[1]).to match(%r{^svnmucc .*--message test}) + end + it "svnmucc_([['help']],'test',ENV_.new,_,nil,{verbose: true}) should echo params" do + rc, out = _json do |_| + ASF::SVN.svnmucc_([['help']],'test',ENV_.new,_,nil,{verbose: true}) + end + expect(rc).to eq(0) + expect(out).to be_kind_of(Hash) + ts = out['transcript'] + expect(ts).to be_kind_of(Array) + expect(ts[0]).to match(%r{\$ echo}) + # either --password pass or --password-from-stdin {:stdin=>\"pass\"} + # This depends on the order in which the command line is built up + expect(ts[1]).to match(%r{^svnmucc .*--message test .*--username user --password.+pass}) + expect(ts[4]).to eq('usage: svnmucc ACTION...') # output of svnmucc help + end end \ No newline at end of file diff --git a/lib/whimsy/asf/svn.rb b/lib/whimsy/asf/svn.rb index 81508b5..9dcb78b 100644 --- a/lib/whimsy/asf/svn.rb +++ b/lib/whimsy/asf/svn.rb @@ -634,7 +634,10 @@ module ASF # env - environment (username/password) # _ - Wunderbar context # revision - the --revision svnmucc parameter (unless nil) - # temp (optional) - use this temporary directory (and don't remove it) + # options - hash: + # :tmpdir - use this temporary directory (and don't remove it) + # :verbose - if true, show command details + # :dryrun - if true, don't execute command, but show it instead # The commands must themselves be arrays to ensure correct processing of white-space # For example: # commands = [] @@ -642,14 +645,20 @@ module ASF # commands << ['mv',url1,url2] # commands << ['rm',url3] # ASF::SVN.svnmucc_(commands,message,env,_,revision) - def self.svnmucc_(commands, msg, env, _, revision, temp=nil) + def self.svnmucc_(commands, msg, env, _, revision, options={}) raise ArgumentError.new 'commands must be an array' unless Array === commands raise ArgumentError.new 'msg must not be nil' unless msg raise ArgumentError.new 'env must not be nil' unless env raise ArgumentError.new '_ must not be nil' unless _ + bad_keys = options.keys - [:dryrun, :verbose, :tmpdir] + if bad_keys.size > 0 + raise ArgumentError.new "Following options not recognised: #{bad_keys.inspect}" + end + require 'tempfile' + temp = options[:tmpdir] tmpdir = temp ? temp : Dir.mktmpdir.untaint begin @@ -685,10 +694,17 @@ module ASF syscmd << ['--username', env.user, '--password', env.password] end end - if _.instance_of?(Wunderbar::JsonBuilder) or _.instance_of?(Wunderbar::TextBuilder) - _.system syscmd, sysopts, sysopts # needs two hashes + if options[:verbose] + _.system 'echo',[syscmd.flatten,sysopts.to_s] + end + if options[:dryrun] + _.system syscmd.insert(0,'echo') else - _.system syscmd, sysopts + if _.instance_of?(Wunderbar::JsonBuilder) or _.instance_of?(Wunderbar::TextBuilder) + _.system syscmd, sysopts, sysopts # needs two hashes + else + _.system syscmd, sysopts + end end ensure File.delete cmdfile # always drop the command file @@ -772,7 +788,7 @@ module ASF if options[:dryrun] puts cmds # TODO: not sure this is correct for Wunderbar else - rc = ASF::SVN.svnmucc_(cmds,msg,env,_,filerev,tmpdir) + rc = ASF::SVN.svnmucc_(cmds,msg,env,_,filerev,{tmpdir: tmpdir}) raise "svnmucc failure #{rc} committing" unless rc == 0 end ensure